1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-27 15:37:29 +03:00

Add command line override for font system

This commit is contained in:
Wez Furlong 2019-02-20 09:01:36 -08:00
parent 8c821bc9e6
commit 9fa376d2a3
2 changed files with 38 additions and 7 deletions

View File

@ -86,19 +86,40 @@ impl FontSystemSelection {
}
}
}
pub fn variants() -> Vec<&'static str> {
vec![
"FontConfigAndFreeType",
"FontLoaderAndFreeType",
"FontLoaderAndRustType",
"CoreText",
]
}
}
fn new_font_system() -> Box<FontSystem> {
FontSystemSelection::default().new_font_system()
impl std::str::FromStr for FontSystemSelection {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
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<Config>) -> Self {
pub fn new(config: Rc<Config>, system: FontSystemSelection) -> Self {
Self {
config,
fonts: RefCell::new(HashMap::new()),
system: new_font_system(),
system: system.new_font_system(),
}
}

View File

@ -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<GuiSelection>,
#[structopt(
long = "font-system",
raw(
possible_values = "&FontSystemSelection::variants()",
case_insensitive = "true"
)
)]
font_system: Option<FontSystemSelection>,
/// 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())