Allow specifying the gui system via the cli

This commit is contained in:
Wez Furlong committed 2019-02-20 08:53:59 -08:00
1 parent b0c2704118
commit 8c821bc9e6
2 files changed
+32 -2

No files matched your search

+20
View File
@@ -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<Self, Self::Err> {
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 {
+12 -2
View File
@@ -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<GuiSelection>,
/// 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)