diff options
| author | Jonah Caplan <jonahcaplan@gmail.com> | 2021-03-08 04:06:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-08 10:06:23 +0100 |
| commit | 44b0246e91ae65b09f3e2d9b111772a6b093135b (patch) | |
| tree | c1a422e0f9ffb02cb978ae4d5bb68018deb2a998 /src/common/input | |
| parent | New tab styling (#216) (diff) | |
| download | sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.tar.gz sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.tar.xz sl0ppij-44b0246e91ae65b09f3e2d9b111772a6b093135b.zip | |
feat(tabs): add ability to set tab name (#212)
* send all tabs in vec
* works but no input filtering
* add event types
* add event handler for tab events
* fmt fixups
* update tab name in place, and escape rename works
* rename handle_tab_event handle_tab_rename_keypress
* handle empty new_name when renaming
* fix(tabs): pad active tab name too
* fix(tabs): report proper length
* fix(tabs): always render active tab
* style(fmt): rustfmt
Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'src/common/input')
| -rw-r--r-- | src/common/input/actions.rs | 2 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 29 | ||||
| -rw-r--r-- | src/common/input/keybinds.rs | 25 |
3 files changed, 55 insertions, 1 deletions
diff --git a/src/common/input/actions.rs b/src/common/input/actions.rs index fe5e2dad..88a7036f 100644 --- a/src/common/input/actions.rs +++ b/src/common/input/actions.rs @@ -48,4 +48,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 5c4f1971..52db9b4f 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -7,7 +7,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}; @@ -232,6 +232,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 => {} } @@ -265,6 +287,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, @@ -310,10 +333,14 @@ 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())); diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index e56488b4..46abf4ab 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -128,6 +128,13 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> { 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'), @@ -155,6 +162,23 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result<ModeKeybinds, String> { ); defaults.insert(Key::Esc, vec![Action::SwitchToMode(InputMode::Command)]); } + 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::TabNameInput(vec![0x1b]), + Action::SwitchToMode(InputMode::Tab), + ], + ); + } } Ok(defaults) @@ -178,6 +202,7 @@ pub fn key_to_actions( }; match *mode { InputMode::Normal => mode_keybind_or_action(Action::Write(input)), + InputMode::RenameTab => mode_keybind_or_action(Action::TabNameInput(input)), _ => mode_keybind_or_action(Action::NoOp), } } |
