From 1edfef4a32d27af907525c49f01b87be0d94bfb3 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 2 Jan 2017 20:42:57 -0800 Subject: Have default mouse and key bindings This improves the situation where the user has not installed the default configuration file. Resolves #42. --- src/config.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 55e69c90..afbae8a3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -188,17 +188,32 @@ pub struct Config { colors: ColorList, /// Keybindings - #[serde(default)] + #[serde(default="default_key_bindings")] key_bindings: Vec, /// Bindings for the mouse - #[serde(default)] + #[serde(default="default_mouse_bindings")] mouse_bindings: Vec, /// Path where config was loaded from config_path: Option, } +static DEFAULT_ALACRITTY_CONFIG: &'static str = include_str!("../alacritty.yml"); + +fn default_config() -> Config { + serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG) + .expect("default config is valid") +} + +fn default_key_bindings() -> Vec { + default_config().key_bindings +} + +fn default_mouse_bindings() -> Vec { + default_config().mouse_bindings +} + impl Default for Config { fn default() -> Config { Config { @@ -1158,6 +1173,12 @@ mod tests { println!("config: {:#?}", config); } + + #[test] + fn defaults_are_ok() { + super::default_key_bindings(); + super::default_mouse_bindings(); + } } #[cfg_attr(feature = "clippy", allow(enum_variant_names))] @@ -1478,3 +1499,4 @@ impl Key { } } } + -- cgit