diff --git a/src/config.rs b/src/config.rs index 3e0e398ee..8a61068b7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -80,14 +80,46 @@ impl Default for Config { } } +#[cfg(target_os = "macos")] +const FONT_FAMILY: &str = "Menlo"; +#[cfg(not(target_os = "macos"))] +const FONT_FAMILY: &str = "monospace"; + +#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] +pub struct FontAttributes { + /// The font family name + pub family: String, + /// Whether the font should be a bold variant + pub bold: Option, + /// Whether the font should be an italic variant + pub italic: Option, +} + +impl Default for FontAttributes { + fn default() -> Self { + Self { + family: FONT_FAMILY.into(), + bold: None, + italic: None, + } + } +} + +fn default_fontconfig_pattern() -> String { + FONT_FAMILY.into() +} + /// Represents textual styling. #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] pub struct TextStyle { /// A font config pattern to parse to locate the font. /// Note that the dpi and current font_size for the terminal /// will be set on the parsed result. + #[serde(default = "default_fontconfig_pattern")] pub fontconfig_pattern: String, + pub font: Vec, + /// If set, when rendering text that is set to the default /// foreground color, use this color instead. This is most /// useful in a `[[font_rules]]` section to implement changing @@ -98,8 +130,9 @@ pub struct TextStyle { impl Default for TextStyle { fn default() -> Self { Self { - fontconfig_pattern: "monospace".into(), + fontconfig_pattern: FONT_FAMILY.into(), foreground: None, + font: vec![FontAttributes::default()], } } } @@ -114,6 +147,15 @@ impl TextStyle { Self { fontconfig_pattern: format!("{}:weight=bold", self.fontconfig_pattern), foreground: self.foreground, + font: self + .font + .iter() + .map(|attr| { + let mut attr = attr.clone(); + attr.bold = Some(true); + attr + }) + .collect(), } } @@ -126,6 +168,15 @@ impl TextStyle { Self { fontconfig_pattern: format!("{}:style=Italic", self.fontconfig_pattern), foreground: self.foreground, + font: self + .font + .iter() + .map(|attr| { + let mut attr = attr.clone(); + attr.italic = Some(true); + attr + }) + .collect(), } } } @@ -204,7 +255,11 @@ impl Config { return Ok(cfg.compute_extra_defaults()); } - Ok(Self::default().compute_extra_defaults()) + Ok(Self::default_config()) + } + + pub fn default_config() -> Self { + Self::default().compute_extra_defaults() } /// In some cases we need to compute expanded values based diff --git a/src/font/rtype.rs b/src/font/rtype.rs index d29e4ada8..413f879ce 100644 --- a/src/font/rtype.rs +++ b/src/font/rtype.rs @@ -28,17 +28,24 @@ impl RustTypeFonts { impl FontSystem for RustTypeFonts { fn load_font(&self, config: &Config, style: &TextStyle) -> Result, Error> { - #[cfg(not(target_os = "macos"))] - let family = "monospace"; - #[cfg(target_os = "macos")] - let family = "Menlo"; - let font_props = system_fonts::FontPropertyBuilder::new() - //.family(&style.fontconfig_pattern) - .family(family) - .monospace() - .build(); + let font = &style.font[0]; + let mut font_props = system_fonts::FontPropertyBuilder::new() + .family(&font.family) + .monospace(); + font_props = if *font.bold.as_ref().unwrap_or(&false) { + font_props.bold() + } else { + font_props + }; + font_props = if *font.italic.as_ref().unwrap_or(&false) { + font_props.italic() + } else { + font_props + }; + let font_props = font_props.build(); + let (data, idx) = system_fonts::get(&font_props) - .ok_or_else(|| format_err!("no font matching {:?}", family))?; + .ok_or_else(|| format_err!("no font matching {:?} {:?}", font_props, font))?; eprintln!("want idx {} in bytes of len {}", idx, data.len()); let collection = FontCollection::from_bytes(data)?; let font = collection.font_at(idx as usize)?; diff --git a/src/main.rs b/src/main.rs index 3201cdc55..04aad7800 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,13 +122,22 @@ fn main() -> Result<(), Error> { "Wez's Terminal Emulator\n\ http://github.com/wez/wezterm", ) + .arg( + Arg::with_name("SKIP_CONFIG") + .short("n") + .help("Skip loading ~/.wezterm.toml"), + ) .arg(Arg::with_name("PROG").multiple(true).help( "Instead of executing your shell, run PROG. \ For example: `wezterm -- bash -l` will spawn bash \ as if it were a login shell.", )) .get_matches(); - let config = Rc::new(config::Config::load()?); + let config = Rc::new(if args.is_present("SKIP_CONFIG") { + config::Config::default_config() + } else { + config::Config::load()? + }); println!("Using configuration: {:#?}", config); let fontconfig = Rc::new(FontConfiguration::new(Rc::clone(&config)));