From 0d16478f5d997b6da5488885e15bfb09ca8e7f6d Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 17 Jan 2019 09:17:26 +0000 Subject: Make all configuration fields optional All configuration fields now have fallback values which will be used if the field is not present. This includes mouse, key bindings and platform specific differences. The mouse and key bindings are now filled by default, if the user rebinds a default mapping, it will be overwritten. To unbind a default binding, it can be mapped to `chars: ""`. Since all platform differences can now be correctly handled by the `src/config/mod.rs` code, it's no longer necessary to maintain separate configuration files, so the `alacritty_macos.yml` and `alacritty_windows.yml` have been deleted. Fixes #40. Fixes #1923. --- src/input.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index be8ed0d1..c2473448 100644 --- a/src/input.rs +++ b/src/input.rs @@ -81,7 +81,7 @@ pub trait ActionContext { /// Describes a state and action to take in that state /// /// This is the shared component of `MouseBinding` and `KeyBinding` -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Binding { /// Modifier keys required to activate binding pub mods: ModifiersState, @@ -107,6 +107,30 @@ pub type KeyBinding = Binding; /// Bindings that are triggered by a mouse button pub type MouseBinding = Binding; +impl Default for KeyBinding { + fn default() -> KeyBinding { + KeyBinding { + mods: Default::default(), + action: Action::Esc(String::new()), + mode: TermMode::NONE, + notmode: TermMode::NONE, + trigger: Key::A, + } + } +} + +impl Default for MouseBinding { + fn default() -> MouseBinding { + MouseBinding { + mods: Default::default(), + action: Action::Esc(String::new()), + mode: TermMode::NONE, + notmode: TermMode::NONE, + trigger: MouseButton::Left, + } + } +} + impl Binding { #[inline] fn is_triggered_by( @@ -124,6 +148,14 @@ impl Binding { self.not_mode_matches(mode) && self.mods_match(mods, relaxed) } + + #[inline] + pub fn triggers_match(&self, binding: &Binding) -> bool { + self.trigger == binding.trigger + && self.mode == binding.mode + && self.notmode == binding.notmode + && self.mods == binding.mods + } } impl Binding { @@ -154,7 +186,7 @@ impl Binding { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Action { /// Write an escape sequence Esc(String), @@ -206,6 +238,15 @@ pub enum Action { /// Spawn a new instance of Alacritty. SpawnNewInstance, + + /// No action. + None, +} + +impl Default for Action { + fn default() -> Action { + Action::None + } } impl Action { @@ -287,6 +328,7 @@ impl Action { Action::SpawnNewInstance => { ctx.spawn_new_instance(); }, + Action::None => (), } } -- cgit