aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/input
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-03-11 22:43:43 +0100
committera-kenji <aks.kenji@protonmail.com>2021-03-11 22:43:43 +0100
commitacc2524105f811d1b32e3b993d91c67968efe33e (patch)
tree7cc1220bcbcc03e8e182572b893ac3c1526662d6 /src/common/input
parentPoking (diff)
parentdocs(readme): update demo gif (diff)
downloadsl0ppij-acc2524105f811d1b32e3b993d91c67968efe33e.tar.gz
sl0ppij-acc2524105f811d1b32e3b993d91c67968efe33e.tar.xz
sl0ppij-acc2524105f811d1b32e3b993d91c67968efe33e.zip
Merge 'upstream/main' into config-file
Diffstat (limited to 'src/common/input')
-rw-r--r--src/common/input/actions.rs2
-rw-r--r--src/common/input/handler.rs53
-rw-r--r--src/common/input/keybinds.rs175
3 files changed, 170 insertions, 60 deletions
diff --git a/src/common/input/actions.rs b/src/common/input/actions.rs
index 6d5c5892..a8a3d600 100644
--- a/src/common/input/actions.rs
+++ b/src/common/input/actions.rs
@@ -50,4 +50,6 @@ pub enum Action {
/// Close the current tab.
CloseTab,
GoToTab(u32),
+ TabNameInput(Vec<u8>),
+ SaveTabName,
}
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 3438bba8..862cc0d2 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -8,7 +8,7 @@ use crate::errors::ContextType;
use crate::os_input_output::OsApi;
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
-use crate::wasm_vm::PluginInstruction;
+use crate::wasm_vm::{EventType, PluginInputType, PluginInstruction};
use crate::CommandIsExecuting;
use serde::{Deserialize, Serialize};
@@ -231,6 +231,28 @@ impl InputHandler {
.send(ScreenInstruction::GoToTab(i))
.unwrap();
}
+ Action::TabNameInput(c) => {
+ self.send_plugin_instructions
+ .send(PluginInstruction::Input(
+ PluginInputType::Event(EventType::Tab),
+ c.clone(),
+ ))
+ .unwrap();
+ self.send_screen_instructions
+ .send(ScreenInstruction::UpdateTabName(c))
+ .unwrap();
+ }
+ Action::SaveTabName => {
+ self.send_plugin_instructions
+ .send(PluginInstruction::Input(
+ PluginInputType::Event(EventType::Tab),
+ vec![b'\n'],
+ ))
+ .unwrap();
+ self.send_screen_instructions
+ .send(ScreenInstruction::UpdateTabName(vec![b'\n']))
+ .unwrap();
+ }
Action::NoOp => {}
}
@@ -249,13 +271,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.
@@ -264,6 +285,7 @@ pub enum InputMode {
Tab,
/// `Scroll` mode allows scrolling up and down within a pane.
Scroll,
+ RenameTab,
}
/// Represents the contents of the help message that is printed in the status bar,
@@ -287,12 +309,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()));
}
@@ -300,8 +317,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()));
}
@@ -309,13 +326,15 @@ pub fn get_help(mode: InputMode) -> Help {
keybinds.push(("←↓↑→".to_string(), "Move focus".to_string()));
keybinds.push(("n".to_string(), "New".to_string()));
keybinds.push(("x".to_string(), "Close".to_string()));
+ keybinds.push(("r".to_string(), "Rename".to_string()));
}
InputMode::Scroll => {
keybinds.push(("↓↑".to_string(), "Scroll".to_string()));
}
+ InputMode::RenameTab => {
+ 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 de75c38f..d7f64652 100644
--- a/src/common/input/keybinds.rs
+++ b/src/common/input/keybinds.rs
@@ -77,28 +77,52 @@ impl Keybinds {
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)]);
@@ -108,20 +132,36 @@ impl Keybinds {
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)]);
@@ -132,11 +172,6 @@ impl Keybinds {
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))]);
@@ -145,17 +180,37 @@ impl Keybinds {
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]);
@@ -166,14 +221,16 @@ impl Keybinds {
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]);
+ defaults.insert(
+ Key::Char('r'),
+ vec![
+ Action::SwitchToMode(InputMode::RenameTab),
+ Action::TabNameInput(vec![0]),
+ ],
+ );
defaults.insert(Key::Char('q'), vec![Action::Quit]);
defaults.insert(
Key::Ctrl('g'),
@@ -182,24 +239,55 @@ impl Keybinds {
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]);
+ }
+ InputMode::RenameTab => {
+ defaults.insert(
+ Key::Char('\n'),
+ vec![Action::SaveTabName, Action::SwitchToMode(InputMode::Tab)],
+ );
defaults.insert(
Key::Ctrl('g'),
vec![Action::SwitchToMode(InputMode::Normal)],
);
- defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Command)]);
+ defaults.insert(
+ Key::Esc,
+ vec![
+ Action::TabNameInput(vec![0x1b]),
+ Action::SwitchToMode(InputMode::Tab),
+ ],
+ );
}
}
ModeKeybinds(defaults)
@@ -224,7 +312,8 @@ impl Keybinds {
.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),
}
}