diff --git a/src/guiloop/mod.rs b/src/guiloop/mod.rs index bc239a6ab..373dbb32b 100644 --- a/src/guiloop/mod.rs +++ b/src/guiloop/mod.rs @@ -35,6 +35,26 @@ impl GuiSelection { } } } + + // TODO: find or build a proc macro for this + pub fn variants() -> Vec<&'static str> { + vec!["Glutin", "X11"] + } +} + +impl std::str::FromStr for GuiSelection { + type Err = Error; + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_ref() { + "glutin" => Ok(GuiSelection::Glutin), + "x11" => Ok(GuiSelection::X11), + _ => Err(format_err!( + "{} is not a valid GuiSelection variant, possible values are {:?}", + s, + GuiSelection::variants() + )), + } + } } pub trait GuiSystem { diff --git a/src/main.rs b/src/main.rs index 2aa4d1c64..d39d59892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ mod futurecore; mod gliumwindows; mod guiloop; mod opengl; - +use crate::guiloop::GuiSelection; use crate::guiloop::GuiSystem; mod font; @@ -73,6 +73,15 @@ struct Opt { #[structopt(short = "n")] skip_config: bool, + #[structopt( + long = "gui-system", + raw( + possible_values = "&GuiSelection::variants()", + case_insensitive = "true" + ) + )] + gui_system: Option, + /// Instead of executing your shell, run PROG. /// For example: `wezterm -- bash -l` will spawn bash /// as if it were a login shell. @@ -97,7 +106,8 @@ fn main() -> Result<(), Error> { None }; - let gui = config.gui_system.new()?; + let gui_system = opts.gui_system.unwrap_or(config.gui_system); + let gui = gui_system.new()?; spawn_window(&*gui, cmd, &config, &fontconfig)?; gui.run_forever(&config, &fontconfig)