diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-01-17 09:17:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-17 09:17:26 +0000 |
commit | 0d16478f5d997b6da5488885e15bfb09ca8e7f6d (patch) | |
tree | 9905e264149d5955ce1161ecf41ad2f23ec9ec91 /src/input.rs | |
parent | 5864c30a54b250163c3a94f053f5f1b907adf9c9 (diff) | |
download | alacritty-0d16478f5d997b6da5488885e15bfb09ca8e7f6d.tar.gz alacritty-0d16478f5d997b6da5488885e15bfb09ca8e7f6d.zip |
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.
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 46 |
1 files changed, 44 insertions, 2 deletions
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<T> { /// Modifier keys required to activate binding pub mods: ModifiersState, @@ -107,6 +107,30 @@ pub type KeyBinding = Binding<Key>; /// Bindings that are triggered by a mouse button pub type MouseBinding = Binding<MouseButton>; +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<T: Eq> Binding<T> { #[inline] fn is_triggered_by( @@ -124,6 +148,14 @@ impl<T: Eq> Binding<T> { self.not_mode_matches(mode) && self.mods_match(mods, relaxed) } + + #[inline] + pub fn triggers_match(&self, binding: &Binding<T>) -> bool { + self.trigger == binding.trigger + && self.mode == binding.mode + && self.notmode == binding.notmode + && self.mods == binding.mods + } } impl<T> Binding<T> { @@ -154,7 +186,7 @@ impl<T> Binding<T> { } } -#[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 => (), } } |