From f6df6e9dc890b129dbf05a0bb9f4dfe2b5a8f408 Mon Sep 17 00:00:00 2001 From: Dante Pippi <6619666+dantepippi@users.noreply.github.com> Date: Wed, 28 Apr 2021 11:41:48 -0300 Subject: [PATCH] Defining sync keybind using default.yaml --- assets/config/default.yaml | 2 + src/common/input/keybinds.rs | 273 ----------------------------------- 2 files changed, 2 insertions(+), 273 deletions(-) diff --git a/assets/config/default.yaml b/assets/config/default.yaml index a3a0242f2..d7360c587 100644 --- a/assets/config/default.yaml +++ b/assets/config/default.yaml @@ -97,6 +97,8 @@ keybinds: key: [Char: 'r',] - action: [CloseFocus,] key: [Char: 'x',] + - action: [ToggleActiveSyncPanes] + key: [Char: 's'] - action: [ToggleFocusFullscreen,] key: [Char: 'f',] - action: [FocusPreviousPane,] diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index a3b710cf6..9842fbe27 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -105,279 +105,6 @@ impl Keybinds { keybinds } - /// Returns the default keybinds for a given [`InputMode`]. - fn get_defaults_for_mode(mode: &InputMode) -> ModeKeybinds { - let mut defaults = HashMap::new(); - - match *mode { - InputMode::Normal => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Locked)], - ); - defaults.insert(Key::Ctrl('p'), vec![Action::SwitchToMode(InputMode::Pane)]); - defaults.insert( - Key::Ctrl('r'), - vec![Action::SwitchToMode(InputMode::Resize)], - ); - defaults.insert(Key::Ctrl('t'), vec![Action::SwitchToMode(InputMode::Tab)]); - defaults.insert( - Key::Ctrl('s'), - vec![Action::SwitchToMode(InputMode::Scroll)], - ); - defaults.insert(Key::Ctrl('q'), vec![Action::Quit]); - - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - InputMode::Locked => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - } - InputMode::Resize => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Locked)], - ); - defaults.insert(Key::Ctrl('p'), vec![Action::SwitchToMode(InputMode::Pane)]); - defaults.insert( - Key::Ctrl('r'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert(Key::Ctrl('t'), vec![Action::SwitchToMode(InputMode::Tab)]); - defaults.insert( - Key::Ctrl('s'), - vec![Action::SwitchToMode(InputMode::Scroll)], - ); - defaults.insert(Key::Ctrl('q'), vec![Action::Quit]); - defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Normal)]); - defaults.insert( - Key::Char('\n'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Char(' '), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - - defaults.insert(Key::Char('h'), vec![Action::Resize(Direction::Left)]); - defaults.insert(Key::Char('j'), vec![Action::Resize(Direction::Down)]); - defaults.insert(Key::Char('k'), vec![Action::Resize(Direction::Up)]); - defaults.insert(Key::Char('l'), vec![Action::Resize(Direction::Right)]); - - defaults.insert(Key::Left, vec![Action::Resize(Direction::Left)]); - defaults.insert(Key::Down, vec![Action::Resize(Direction::Down)]); - defaults.insert(Key::Up, vec![Action::Resize(Direction::Up)]); - defaults.insert(Key::Right, vec![Action::Resize(Direction::Right)]); - - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - InputMode::Pane => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Locked)], - ); - defaults.insert( - Key::Ctrl('p'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Ctrl('r'), - vec![Action::SwitchToMode(InputMode::Resize)], - ); - defaults.insert(Key::Ctrl('t'), vec![Action::SwitchToMode(InputMode::Tab)]); - defaults.insert( - Key::Ctrl('s'), - vec![Action::SwitchToMode(InputMode::Scroll)], - ); - defaults.insert(Key::Ctrl('q'), vec![Action::Quit]); - defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Normal)]); - defaults.insert( - Key::Char('\n'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Char(' '), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - - defaults.insert(Key::Char('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Char('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Char('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Char('l'), vec![Action::MoveFocus(Direction::Right)]); - - defaults.insert(Key::Left, vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Down, vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Up, vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Right, vec![Action::MoveFocus(Direction::Right)]); - - defaults.insert(Key::Char('p'), vec![Action::SwitchFocus]); - defaults.insert(Key::Char('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Char('d'), vec![Action::NewPane(Some(Direction::Down))]); - defaults.insert( - Key::Char('r'), - vec![Action::NewPane(Some(Direction::Right))], - ); - defaults.insert(Key::Char('x'), vec![Action::CloseFocus]); - defaults.insert(Key::Char('s'), vec![Action::ToggleActiveSyncPanes]); - defaults.insert(Key::Char('f'), vec![Action::ToggleFocusFullscreen]); - - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - InputMode::Tab => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Locked)], - ); - defaults.insert(Key::Ctrl('p'), vec![Action::SwitchToMode(InputMode::Pane)]); - defaults.insert( - Key::Ctrl('r'), - vec![Action::SwitchToMode(InputMode::Resize)], - ); - defaults.insert( - Key::Ctrl('t'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Ctrl('s'), - vec![Action::SwitchToMode(InputMode::Scroll)], - ); - defaults.insert(Key::Ctrl('q'), vec![Action::Quit]); - defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Normal)]); - defaults.insert( - Key::Char('\n'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Char(' '), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - - defaults.insert(Key::Char('h'), vec![Action::GoToPreviousTab]); - defaults.insert(Key::Char('j'), vec![Action::GoToNextTab]); - defaults.insert(Key::Char('k'), vec![Action::GoToPreviousTab]); - defaults.insert(Key::Char('l'), vec![Action::GoToNextTab]); - - defaults.insert(Key::Left, vec![Action::GoToPreviousTab]); - defaults.insert(Key::Down, vec![Action::GoToNextTab]); - defaults.insert(Key::Up, vec![Action::GoToPreviousTab]); - defaults.insert(Key::Right, vec![Action::GoToNextTab]); - - defaults.insert(Key::Char('n'), vec![Action::NewTab]); - defaults.insert(Key::Char('x'), vec![Action::CloseTab]); - - defaults.insert( - Key::Char('r'), - vec![ - Action::SwitchToMode(InputMode::RenameTab), - Action::TabNameInput(vec![0]), - ], - ); - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - for i in '1'..='9' { - defaults.insert(Key::Char(i), vec![Action::GoToTab(i.to_digit(10).unwrap())]); - } - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - InputMode::Scroll => { - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Locked)], - ); - defaults.insert(Key::Ctrl('p'), vec![Action::SwitchToMode(InputMode::Pane)]); - defaults.insert( - Key::Ctrl('r'), - vec![Action::SwitchToMode(InputMode::Resize)], - ); - defaults.insert(Key::Ctrl('t'), vec![Action::SwitchToMode(InputMode::Tab)]); - defaults.insert( - Key::Ctrl('s'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert(Key::Ctrl('q'), vec![Action::Quit]); - defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Normal)]); - defaults.insert( - Key::Char('\n'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Char(' '), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - - defaults.insert(Key::Char('j'), vec![Action::ScrollDown]); - defaults.insert(Key::Char('k'), vec![Action::ScrollUp]); - - defaults.insert(Key::Ctrl('f'), vec![Action::PageScrollDown]); - defaults.insert(Key::Ctrl('b'), vec![Action::PageScrollUp]); - defaults.insert(Key::PageDown, vec![Action::PageScrollDown]); - defaults.insert(Key::PageUp, vec![Action::PageScrollUp]); - - defaults.insert(Key::Down, vec![Action::ScrollDown]); - defaults.insert(Key::Up, vec![Action::ScrollUp]); - - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - InputMode::RenameTab => { - defaults.insert(Key::Char('\n'), vec![Action::SwitchToMode(InputMode::Tab)]); - defaults.insert( - Key::Ctrl('g'), - vec![Action::SwitchToMode(InputMode::Normal)], - ); - defaults.insert( - Key::Esc, - vec![ - Action::TabNameInput(vec![0x1b]), - Action::SwitchToMode(InputMode::Tab), - ], - ); - - defaults.insert(Key::Alt('n'), vec![Action::NewPane(None)]); - defaults.insert(Key::Alt('h'), vec![Action::MoveFocus(Direction::Left)]); - defaults.insert(Key::Alt('j'), vec![Action::MoveFocus(Direction::Down)]); - defaults.insert(Key::Alt('k'), vec![Action::MoveFocus(Direction::Up)]); - defaults.insert(Key::Alt('l'), vec![Action::MoveFocus(Direction::Right)]); - defaults.insert(Key::Alt('['), vec![Action::FocusPreviousPane]); - defaults.insert(Key::Alt(']'), vec![Action::FocusNextPane]); - } - } - ModeKeybinds(defaults) - } - /// Converts a [`Key`] terminal event to a sequence of [`Action`]s according to the current /// [`InputMode`] and [`Keybinds`]. pub fn key_to_actions(