aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/input
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2021-03-11 16:03:28 +0100
committerGitHub <noreply@github.com>2021-03-11 16:03:28 +0100
commit8d0ff0fe405b4a6878cde34269a1ddb9e8cc3f0d (patch)
tree7d183a5e05a4b070a9e0327719e177cbf07c8dac /src/common/input
parentfeat(tabs): add ability to set tab name (#212) (diff)
downloadsl0ppij-8d0ff0fe405b4a6878cde34269a1ddb9e8cc3f0d.tar.gz
sl0ppij-8d0ff0fe405b4a6878cde34269a1ddb9e8cc3f0d.tar.xz
sl0ppij-8d0ff0fe405b4a6878cde34269a1ddb9e8cc3f0d.zip
feat(input): new shortcuts and ui (#220)
* feat(statusbar): new shortcuts * feat(input): new shortcuts and ui * style(fmt): rustfmt
Diffstat (limited to 'src/common/input')
-rw-r--r--src/common/input/handler.rs24
-rw-r--r--src/common/input/keybinds.rs158
2 files changed, 119 insertions, 63 deletions
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 52db9b4f..57bb46fb 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -272,13 +272,12 @@ impl InputHandler {
/// Describes the different input modes, which change the way that keystrokes will be interpreted.
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, EnumIter, Serialize, Deserialize)]
pub enum InputMode {
- /// In `Normal` mode, input is always written to the terminal, except for one special input that
- /// triggers the switch to [`InputMode::Command`] mode.
+ /// In `Normal` mode, input is always written to the terminal, except for the shortcuts leading
+ /// to other modes
Normal,
- /// In `Command` mode, input is bound to actions (more precisely, sequences of actions).
- /// `Command` mode gives access to the other modes non-`InputMode::Normal` modes.
- /// etc.
- Command,
+ /// In `Locked` mode, input is always written to the terminal and all shortcuts are disabled
+ /// except the one leading back to normal mode
+ Locked,
/// `Resize` mode allows resizing the different existing panes.
Resize,
/// `Pane` mode allows creating and closing panes, as well as moving between them.
@@ -311,12 +310,7 @@ impl Default for InputMode {
pub fn get_help(mode: InputMode) -> Help {
let mut keybinds: Vec<(String, String)> = vec![];
match mode {
- InputMode::Normal | InputMode::Command => {
- keybinds.push(("p".to_string(), "PANE".to_string()));
- keybinds.push(("t".to_string(), "TAB".to_string()));
- keybinds.push(("r".to_string(), "RESIZE".to_string()));
- keybinds.push(("s".to_string(), "SCROLL".to_string()));
- }
+ InputMode::Normal | InputMode::Locked => {}
InputMode::Resize => {
keybinds.push(("←↓↑→".to_string(), "Resize".to_string()));
}
@@ -324,8 +318,8 @@ pub fn get_help(mode: InputMode) -> Help {
keybinds.push(("←↓↑→".to_string(), "Move focus".to_string()));
keybinds.push(("p".to_string(), "Next".to_string()));
keybinds.push(("n".to_string(), "New".to_string()));
- keybinds.push(("d".to_string(), "Split down".to_string()));
- keybinds.push(("r".to_string(), "Split right".to_string()));
+ keybinds.push(("d".to_string(), "Down split".to_string()));
+ keybinds.push(("r".to_string(), "Right split".to_string()));
keybinds.push(("x".to_string(), "Close".to_string()));
keybinds.push(("f".to_string(), "Fullscreen".to_string()));
}
@@ -342,8 +336,6 @@ pub fn get_help(mode: InputMode) -> Help {
keybinds.push(("Enter".to_string(), "when done".to_string()));
}
}
- keybinds.push(("ESC".to_string(), "BACK".to_string()));
- keybinds.push(("q".to_string(), "QUIT".to_string()));
Help { mode, keybinds }
}
diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs
index 46abf4ab..4b676037 100644
--- a/src/common/input/keybinds.rs
+++ b/src/common/input/keybinds.rs
@@ -31,28 +31,52 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
InputMode::Normal => {
defaults.insert(
Key::Ctrl('g'),
- vec![Action::SwitchToMode(InputMode::Command)],
+ vec![Action::SwitchToMode(InputMode::Locked)],
);
- }
- InputMode::Command => {
+ defaults.insert(Key::Ctrl('p'), vec![Action::SwitchToMode(InputMode::Pane)]);
defaults.insert(
- Key::Char('r'),
+ Key::Ctrl('r'),
vec![Action::SwitchToMode(InputMode::Resize)],
);
- defaults.insert(Key::Char('p'), vec![Action::SwitchToMode(InputMode::Pane)]);
- defaults.insert(Key::Char('t'), vec![Action::SwitchToMode(InputMode::Tab)]);
+ defaults.insert(Key::Ctrl('t'), vec![Action::SwitchToMode(InputMode::Tab)]);
defaults.insert(
- Key::Char('s'),
+ Key::Ctrl('s'),
vec![Action::SwitchToMode(InputMode::Scroll)],
);
+ defaults.insert(Key::Ctrl('q'), vec![Action::Quit]);
+ }
+ InputMode::Locked => {
defaults.insert(
Key::Ctrl('g'),
vec![Action::SwitchToMode(InputMode::Normal)],
);
- defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Normal)]);
- defaults.insert(Key::Char('q'), vec![Action::Quit]);
}
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)]);
@@ -62,20 +86,36 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
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::Ctrl('b'), vec![Action::Resize(Direction::Left)]);
- defaults.insert(Key::Ctrl('n'), vec![Action::Resize(Direction::Down)]);
- defaults.insert(Key::Ctrl('p'), vec![Action::Resize(Direction::Up)]);
- defaults.insert(Key::Ctrl('f'), vec![Action::Resize(Direction::Right)]);
-
- defaults.insert(Key::Char('q'), vec![Action::Quit]);
+ }
+ 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::Esc, vec![Action::SwitchToMode(InputMode::Command)]);
- }
- 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::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)]);
@@ -86,11 +126,6 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
defaults.insert(Key::Up, vec![Action::MoveFocus(Direction::Up)]);
defaults.insert(Key::Right, vec![Action::MoveFocus(Direction::Right)]);
- defaults.insert(Key::Ctrl('b'), vec![Action::MoveFocus(Direction::Left)]);
- defaults.insert(Key::Ctrl('n'), vec![Action::MoveFocus(Direction::Down)]);
- defaults.insert(Key::Ctrl('p'), vec![Action::MoveFocus(Direction::Up)]);
- defaults.insert(Key::Ctrl('f'), vec![Action::MoveFocus(Direction::Right)]);
-
defaults.insert(Key::Char('p'), vec![Action::SwitchFocus(Direction::Right)]);
defaults.insert(Key::Char('n'), vec![Action::NewPane(None)]);
defaults.insert(Key::Char('d'), vec![Action::NewPane(Some(Direction::Down))]);
@@ -99,17 +134,37 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
vec![Action::NewPane(Some(Direction::Right))],
);
defaults.insert(Key::Char('x'), vec![Action::CloseFocus]);
-
defaults.insert(Key::Char('f'), vec![Action::ToggleFocusFullscreen]);
-
- defaults.insert(Key::Char('q'), vec![Action::Quit]);
+ }
+ 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::Esc, vec![Action::SwitchToMode(InputMode::Command)]);
- }
- 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::GoToPreviousTab]);
defaults.insert(Key::Char('j'), vec![Action::GoToNextTab]);
defaults.insert(Key::Char('k'), vec![Action::GoToPreviousTab]);
@@ -120,11 +175,6 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
defaults.insert(Key::Up, vec![Action::GoToPreviousTab]);
defaults.insert(Key::Right, vec![Action::GoToNextTab]);
- defaults.insert(Key::Ctrl('b'), vec![Action::GoToPreviousTab]);
- defaults.insert(Key::Ctrl('n'), vec![Action::GoToNextTab]);
- defaults.insert(Key::Ctrl('p'), vec![Action::GoToPreviousTab]);
- defaults.insert(Key::Ctrl('f'), vec![Action::GoToNextTab]);
-
defaults.insert(Key::Char('n'), vec![Action::NewTab]);
defaults.insert(Key::Char('x'), vec![Action::CloseTab]);
@@ -143,24 +193,38 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> {
for i in '1'..='9' {
defaults.insert(Key::Char(i), vec![Action::GoToTab(i.to_digit(10).unwrap())]);
}
- defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Command)]);
}
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::Down, vec![Action::ScrollDown]);
defaults.insert(Key::Up, vec![Action::ScrollUp]);
-
- defaults.insert(Key::Ctrl('n'), vec![Action::ScrollDown]);
- defaults.insert(Key::Ctrl('p'), vec![Action::ScrollUp]);
-
- defaults.insert(Key::Char('q'), vec![Action::Quit]);
- defaults.insert(
- Key::Ctrl('g'),
- vec![Action::SwitchToMode(InputMode::Normal)],
- );
- defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Command)]);
}
InputMode::RenameTab => {
defaults.insert(
@@ -201,7 +265,7 @@ pub fn key_to_actions(
.unwrap_or_else(|| vec![action])
};
match *mode {
- InputMode::Normal => mode_keybind_or_action(Action::Write(input)),
+ InputMode::Normal | InputMode::Locked => mode_keybind_or_action(Action::Write(input)),
InputMode::RenameTab => mode_keybind_or_action(Action::TabNameInput(input)),
_ => mode_keybind_or_action(Action::NoOp),
}