diff options
Diffstat (limited to 'alacritty/src/config/bindings.rs')
-rw-r--r-- | alacritty/src/config/bindings.rs | 209 |
1 files changed, 87 insertions, 122 deletions
diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index b5680439..dbe5d42e 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -210,10 +210,7 @@ impl RelaxedEq for ModifiersState { // Make sure that modifiers in the config are always present, // but ignore surplus modifiers. fn relaxed_eq(&self, other: Self) -> bool { - (!self.logo || other.logo) - && (!self.alt || other.alt) - && (!self.ctrl || other.ctrl) - && (!self.shift || other.shift) + !*self | other == ModifiersState::all() } } @@ -222,7 +219,7 @@ macro_rules! bindings { $ty:ident; $( $key:path - $(,[$($mod:ident: $enabled:expr),*])* + $(,$mods:expr)* $(,+$mode:expr)* $(,~$notmode:expr)* ;$action:expr @@ -232,10 +229,8 @@ macro_rules! bindings { let mut v = Vec::new(); $( - let mut _mods = ModifiersState { - $($($mod: $enabled),*,)* - ..Default::default() - }; + let mut _mods = ModifiersState::empty(); + $(_mods = $mods;)* let mut _mode = TermMode::empty(); $(_mode = $mode;)* let mut _notmode = TermMode::empty(); @@ -266,25 +261,25 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { KeyBinding; Key::Paste; Action::Paste; Key::Copy; Action::Copy; - Key::L, [ctrl: true]; Action::ClearLogNotice; - Key::L, [ctrl: true]; Action::Esc("\x0c".into()); - Key::PageUp, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollPageUp; - Key::PageDown, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollPageDown; - Key::Home, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollToTop; - Key::End, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollToBottom; + Key::L, ModifiersState::CTRL; Action::ClearLogNotice; + Key::L, ModifiersState::CTRL; Action::Esc("\x0c".into()); + Key::PageUp, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollPageUp; + Key::PageDown, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollPageDown; + Key::Home, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollToTop; + Key::End, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollToBottom; Key::Home, +TermMode::APP_CURSOR; Action::Esc("\x1bOH".into()); Key::Home, ~TermMode::APP_CURSOR; Action::Esc("\x1b[H".into()); - Key::Home, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2H".into()); + Key::Home, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2H".into()); Key::End, +TermMode::APP_CURSOR; Action::Esc("\x1bOF".into()); Key::End, ~TermMode::APP_CURSOR; Action::Esc("\x1b[F".into()); - Key::End, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2F".into()); + Key::End, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2F".into()); Key::PageUp; Action::Esc("\x1b[5~".into()); - Key::PageUp, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[5;2~".into()); + Key::PageUp, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[5;2~".into()); Key::PageDown; Action::Esc("\x1b[6~".into()); - Key::PageDown, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[6;2~".into()); - Key::Tab, [shift: true]; Action::Esc("\x1b[Z".into()); + Key::PageDown, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[6;2~".into()); + Key::Tab, ModifiersState::SHIFT; Action::Esc("\x1b[Z".into()); Key::Back; Action::Esc("\x7f".into()); - Key::Back, [alt: true]; Action::Esc("\x1b\x7f".into()); + Key::Back, ModifiersState::ALT; Action::Esc("\x1b\x7f".into()); Key::Insert; Action::Esc("\x1b[2~".into()); Key::Delete; Action::Esc("\x1b[3~".into()); Key::Up, +TermMode::APP_CURSOR; Action::Esc("\x1bOA".into()); @@ -330,70 +325,45 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { // ---------+--------------------------- // // from: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys - let modifiers = vec![ - ModifiersState { shift: true, ..ModifiersState::default() }, - ModifiersState { alt: true, ..ModifiersState::default() }, - ModifiersState { shift: true, alt: true, ..ModifiersState::default() }, - ModifiersState { ctrl: true, ..ModifiersState::default() }, - ModifiersState { shift: true, ctrl: true, ..ModifiersState::default() }, - ModifiersState { alt: true, ctrl: true, ..ModifiersState::default() }, - ModifiersState { shift: true, alt: true, ctrl: true, ..ModifiersState::default() }, + let mut modifiers = vec![ + ModifiersState::SHIFT, + ModifiersState::ALT, + ModifiersState::SHIFT | ModifiersState::ALT, + ModifiersState::CTRL, + ModifiersState::SHIFT | ModifiersState::CTRL, + ModifiersState::ALT | ModifiersState::CTRL, + ModifiersState::SHIFT | ModifiersState::ALT | ModifiersState::CTRL, ]; - for (index, mods) in modifiers.iter().enumerate() { + for (index, mods) in modifiers.drain(..).enumerate() { let modifiers_code = index + 2; bindings.extend(bindings!( KeyBinding; - Key::Delete, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[3;{}~", modifiers_code)); - Key::Up, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}A", modifiers_code)); - Key::Down, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}B", modifiers_code)); - Key::Right, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}C", modifiers_code)); - Key::Left, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}D", modifiers_code)); - Key::F1, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}P", modifiers_code)); - Key::F2, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}Q", modifiers_code)); - Key::F3, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}R", modifiers_code)); - Key::F4, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}S", modifiers_code)); - Key::F5, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[15;{}~", modifiers_code)); - Key::F6, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[17;{}~", modifiers_code)); - Key::F7, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[18;{}~", modifiers_code)); - Key::F8, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[19;{}~", modifiers_code)); - Key::F9, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[20;{}~", modifiers_code)); - Key::F10, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[21;{}~", modifiers_code)); - Key::F11, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[23;{}~", modifiers_code)); - Key::F12, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[24;{}~", modifiers_code)); - Key::F13, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[25;{}~", modifiers_code)); - Key::F14, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[26;{}~", modifiers_code)); - Key::F15, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[28;{}~", modifiers_code)); - Key::F16, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[29;{}~", modifiers_code)); - Key::F17, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[31;{}~", modifiers_code)); - Key::F18, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[32;{}~", modifiers_code)); - Key::F19, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[33;{}~", modifiers_code)); - Key::F20, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[34;{}~", modifiers_code)); + Key::Delete, mods; Action::Esc(format!("\x1b[3;{}~", modifiers_code)); + Key::Up, mods; Action::Esc(format!("\x1b[1;{}A", modifiers_code)); + Key::Down, mods; Action::Esc(format!("\x1b[1;{}B", modifiers_code)); + Key::Right, mods; Action::Esc(format!("\x1b[1;{}C", modifiers_code)); + Key::Left, mods; Action::Esc(format!("\x1b[1;{}D", modifiers_code)); + Key::F1, mods; Action::Esc(format!("\x1b[1;{}P", modifiers_code)); + Key::F2, mods; Action::Esc(format!("\x1b[1;{}Q", modifiers_code)); + Key::F3, mods; Action::Esc(format!("\x1b[1;{}R", modifiers_code)); + Key::F4, mods; Action::Esc(format!("\x1b[1;{}S", modifiers_code)); + Key::F5, mods; Action::Esc(format!("\x1b[15;{}~", modifiers_code)); + Key::F6, mods; Action::Esc(format!("\x1b[17;{}~", modifiers_code)); + Key::F7, mods; Action::Esc(format!("\x1b[18;{}~", modifiers_code)); + Key::F8, mods; Action::Esc(format!("\x1b[19;{}~", modifiers_code)); + Key::F9, mods; Action::Esc(format!("\x1b[20;{}~", modifiers_code)); + Key::F10, mods; Action::Esc(format!("\x1b[21;{}~", modifiers_code)); + Key::F11, mods; Action::Esc(format!("\x1b[23;{}~", modifiers_code)); + Key::F12, mods; Action::Esc(format!("\x1b[24;{}~", modifiers_code)); + Key::F13, mods; Action::Esc(format!("\x1b[25;{}~", modifiers_code)); + Key::F14, mods; Action::Esc(format!("\x1b[26;{}~", modifiers_code)); + Key::F15, mods; Action::Esc(format!("\x1b[28;{}~", modifiers_code)); + Key::F16, mods; Action::Esc(format!("\x1b[29;{}~", modifiers_code)); + Key::F17, mods; Action::Esc(format!("\x1b[31;{}~", modifiers_code)); + Key::F18, mods; Action::Esc(format!("\x1b[32;{}~", modifiers_code)); + Key::F19, mods; Action::Esc(format!("\x1b[33;{}~", modifiers_code)); + Key::F20, mods; Action::Esc(format!("\x1b[34;{}~", modifiers_code)); )); // We're adding the following bindings with `Shift` manually above, so skipping them here @@ -401,16 +371,11 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { if modifiers_code != 2 { bindings.extend(bindings!( KeyBinding; - Key::Insert, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[2;{}~", modifiers_code)); - Key::PageUp, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[5;{}~", modifiers_code)); - Key::PageDown, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[6;{}~", modifiers_code)); - Key::End, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}F", modifiers_code)); - Key::Home, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}H", modifiers_code)); + Key::Insert, mods; Action::Esc(format!("\x1b[2;{}~", modifiers_code)); + Key::PageUp, mods; Action::Esc(format!("\x1b[5;{}~", modifiers_code)); + Key::PageDown, mods; Action::Esc(format!("\x1b[6;{}~", modifiers_code)); + Key::End, mods; Action::Esc(format!("\x1b[1;{}F", modifiers_code)); + Key::Home, mods; Action::Esc(format!("\x1b[1;{}H", modifiers_code)); )); } } @@ -424,14 +389,14 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { fn common_keybindings() -> Vec<KeyBinding> { bindings!( KeyBinding; - Key::V, [ctrl: true, shift: true]; Action::Paste; - Key::C, [ctrl: true, shift: true]; Action::Copy; - Key::Insert, [shift: true]; Action::PasteSelection; - Key::Key0, [ctrl: true]; Action::ResetFontSize; - Key::Equals, [ctrl: true]; Action::IncreaseFontSize; - Key::Add, [ctrl: true]; Action::IncreaseFontSize; - Key::Subtract, [ctrl: true]; Action::DecreaseFontSize; - Key::Minus, [ctrl: true]; Action::DecreaseFontSize; + Key::V, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Paste; + Key::C, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Copy; + Key::Insert, ModifiersState::SHIFT; Action::PasteSelection; + Key::Key0, ModifiersState::CTRL; Action::ResetFontSize; + Key::Equals, ModifiersState::CTRL; Action::IncreaseFontSize; + Key::Add, ModifiersState::CTRL; Action::IncreaseFontSize; + Key::Subtract, ModifiersState::CTRL; Action::DecreaseFontSize; + Key::Minus, ModifiersState::CTRL; Action::DecreaseFontSize; ) } @@ -444,7 +409,7 @@ pub fn platform_key_bindings() -> Vec<KeyBinding> { pub fn platform_key_bindings() -> Vec<KeyBinding> { let mut bindings = bindings!( KeyBinding; - Key::Return, [alt: true]; Action::ToggleFullscreen; + Key::Return, ModifiersState::ALT; Action::ToggleFullscreen; ); bindings.extend(common_keybindings()); bindings @@ -454,19 +419,19 @@ pub fn platform_key_bindings() -> Vec<KeyBinding> { pub fn platform_key_bindings() -> Vec<KeyBinding> { bindings!( KeyBinding; - Key::Key0, [logo: true]; Action::ResetFontSize; - Key::Equals, [logo: true]; Action::IncreaseFontSize; - Key::Add, [logo: true]; Action::IncreaseFontSize; - Key::Minus, [logo: true]; Action::DecreaseFontSize; - Key::Insert, [shift: true]; Action::Esc("\x1b[2;2~".into()); - Key::F, [ctrl: true, logo: true]; Action::ToggleFullscreen; - Key::K, [logo: true]; Action::ClearHistory; - Key::K, [logo: true]; Action::Esc("\x0c".into()); - Key::V, [logo: true]; Action::Paste; - Key::C, [logo: true]; Action::Copy; - Key::H, [logo: true]; Action::Hide; - Key::Q, [logo: true]; Action::Quit; - Key::W, [logo: true]; Action::Quit; + Key::Key0, ModifiersState::LOGO; Action::ResetFontSize; + Key::Equals, ModifiersState::LOGO; Action::IncreaseFontSize; + Key::Add, ModifiersState::LOGO; Action::IncreaseFontSize; + Key::Minus, ModifiersState::LOGO; Action::DecreaseFontSize; + Key::Insert, ModifiersState::SHIFT; Action::Esc("\x1b[2;2~".into()); + Key::F, ModifiersState::CTRL | ModifiersState::LOGO; Action::ToggleFullscreen; + Key::K, ModifiersState::LOGO; Action::ClearHistory; + Key::K, ModifiersState::LOGO; Action::Esc("\x0c".into()); + Key::V, ModifiersState::LOGO; Action::Paste; + Key::C, ModifiersState::LOGO; Action::Copy; + Key::H, ModifiersState::LOGO; Action::Hide; + Key::Q, ModifiersState::LOGO; Action::Quit; + Key::W, ModifiersState::LOGO; Action::Quit; ) } @@ -1201,13 +1166,13 @@ impl<'a> de::Deserialize<'a> for ModsWrapper { where E: de::Error, { - let mut res = ModifiersState::default(); + let mut res = ModifiersState::empty(); for modifier in value.split('|') { match modifier.trim().to_lowercase().as_str() { - "command" | "super" => res.logo = true, - "shift" => res.shift = true, - "alt" | "option" => res.alt = true, - "control" => res.ctrl = true, + "command" | "super" => res.insert(ModifiersState::LOGO), + "shift" => res.insert(ModifiersState::SHIFT), + "alt" | "option" => res.insert(ModifiersState::ALT), + "control" => res.insert(ModifiersState::CTRL), "none" => (), _ => error!(target: LOG_TARGET_CONFIG, "Unknown modifier {:?}", modifier), } @@ -1265,9 +1230,9 @@ mod test { #[test] fn mods_binding_requires_strict_match() { let mut superset_mods = MockBinding::default(); - superset_mods.mods = ModifiersState { alt: true, logo: true, ctrl: true, shift: true }; + superset_mods.mods = ModifiersState::all(); let mut subset_mods = MockBinding::default(); - subset_mods.mods = ModifiersState { alt: true, logo: false, ctrl: false, shift: false }; + subset_mods.mods = ModifiersState::ALT; assert!(!superset_mods.triggers_match(&subset_mods)); assert!(!subset_mods.triggers_match(&superset_mods)); @@ -1368,10 +1333,10 @@ mod test { #[test] fn binding_trigger_mods() { let mut binding = MockBinding::default(); - binding.mods = ModifiersState { alt: true, logo: true, ctrl: false, shift: false }; + binding.mods = ModifiersState::ALT | ModifiersState::LOGO; - let superset_mods = ModifiersState { alt: true, logo: true, ctrl: true, shift: true }; - let subset_mods = ModifiersState { alt: false, logo: false, ctrl: false, shift: false }; + let superset_mods = ModifiersState::all(); + let subset_mods = ModifiersState::empty(); let t = binding.trigger; let mode = binding.mode; |