diff --git a/src/font/mod.rs b/src/font/mod.rs index d5f231f3c..183468033 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -86,19 +86,40 @@ impl FontSystemSelection { } } } + pub fn variants() -> Vec<&'static str> { + vec![ + "FontConfigAndFreeType", + "FontLoaderAndFreeType", + "FontLoaderAndRustType", + "CoreText", + ] + } } -fn new_font_system() -> Box { - FontSystemSelection::default().new_font_system() +impl std::str::FromStr for FontSystemSelection { + type Err = Error; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_ref() { + "fontconfigandfreetype" => Ok(FontSystemSelection::FontConfigAndFreeType), + "fontloadandfreetype" => Ok(FontSystemSelection::FontLoaderAndFreeType), + "fontloaderandrusttype" => Ok(FontSystemSelection::FontLoaderAndRustType), + "coretext" => Ok(FontSystemSelection::CoreText), + _ => Err(format_err!( + "{} is not a valid FontSystemSelection variant, possible values are {:?}", + s, + FontSystemSelection::variants() + )), + } + } } impl FontConfiguration { /// Create a new empty configuration - pub fn new(config: Rc) -> Self { + pub fn new(config: Rc, system: FontSystemSelection) -> Self { Self { config, fonts: RefCell::new(HashMap::new()), - system: new_font_system(), + system: system.new_font_system(), } } diff --git a/src/main.rs b/src/main.rs index d39d59892..24710fbbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use crate::guiloop::GuiSelection; use crate::guiloop::GuiSystem; mod font; -use crate::font::FontConfiguration; +use crate::font::{FontConfiguration, FontSystemSelection}; mod pty; pub use crate::pty::{openpty, Child, Command, ExitStatus, MasterPty, SlavePty}; @@ -82,6 +82,15 @@ struct Opt { )] gui_system: Option, + #[structopt( + long = "font-system", + raw( + possible_values = "&FontSystemSelection::variants()", + case_insensitive = "true" + ) + )] + font_system: Option, + /// Instead of executing your shell, run PROG. /// For example: `wezterm -- bash -l` will spawn bash /// as if it were a login shell. @@ -96,9 +105,10 @@ fn main() -> Result<(), Error> { } else { config::Config::load()? }); - println!("Using configuration: {:#?}", config); + println!("Using configuration: {:#?}\nopts: {:#?}", config, opts); - let fontconfig = Rc::new(FontConfiguration::new(Rc::clone(&config))); + let font_system = opts.font_system.unwrap_or(config.font_system); + let fontconfig = Rc::new(FontConfiguration::new(Rc::clone(&config), font_system)); let cmd = if opts.prog.len() > 0 { Some(opts.prog.iter().map(|x| x.as_os_str()).collect())