diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-12 20:03:04 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-12 20:03:04 +0200 |
| commit | 4134c952f65aa2951404991bcf525462e3482fe9 (patch) | |
| tree | cf809552c3f676c5dee56873052a5a584e377623 /src/common/input/handler.rs | |
| parent | Add Complile Time System Directories (diff) | |
| parent | Merge pull request #497 from a-kenji/fix-default-keybind (diff) | |
| download | sl0ppij-4134c952f65aa2951404991bcf525462e3482fe9.tar.gz sl0ppij-4134c952f65aa2951404991bcf525462e3482fe9.tar.xz sl0ppij-4134c952f65aa2951404991bcf525462e3482fe9.zip | |
Merge branch 'main' of https://github.com/zellij-org/zellij into set-data-dir
Diffstat (limited to 'src/common/input/handler.rs')
| -rw-r--r-- | src/common/input/handler.rs | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 75f9f8b1..2dbec080 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -4,14 +4,14 @@ use super::actions::Action; use super::keybinds::Keybinds; use crate::client::ClientInstruction; use crate::common::input::config::Config; -use crate::common::{SenderWithContext, OPENCALLS}; +use crate::common::thread_bus::{SenderWithContext, OPENCALLS}; use crate::errors::ContextType; use crate::os_input_output::ClientOsApi; use crate::server::ServerInstruction; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; -use zellij_tile::data::{InputMode, Key, ModeInfo, Palette}; +use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; /// Handles the dispatching of [`Action`]s according to the current /// [`InputMode`], and keep tracks of the current [`InputMode`]. @@ -23,6 +23,7 @@ struct InputHandler { command_is_executing: CommandIsExecuting, send_client_instructions: SenderWithContext<ClientInstruction>, should_exit: bool, + pasting: bool, } impl InputHandler { @@ -40,6 +41,7 @@ impl InputHandler { command_is_executing, send_client_instructions, should_exit: false, + pasting: false, } } @@ -49,6 +51,8 @@ impl InputHandler { let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); err_ctx.add_call(ContextType::StdinHandler); let alt_left_bracket = vec![27, 91]; + let bracketed_paste_start = vec![27, 91, 50, 48, 48, 126]; // \u{1b}[200~ + let bracketed_paste_end = vec![27, 91, 50, 48, 49, 126]; // \u{1b}[201 loop { if self.should_exit { break; @@ -67,6 +71,10 @@ impl InputHandler { if unsupported_key == alt_left_bracket { let key = Key::Alt('['); self.handle_key(&key, raw_bytes); + } else if unsupported_key == bracketed_paste_start { + self.pasting = true; + } else if unsupported_key == bracketed_paste_end { + self.pasting = false; } } termion::event::Event::Mouse(_) => { @@ -81,10 +89,20 @@ impl InputHandler { } fn handle_key(&mut self, key: &Key, raw_bytes: Vec<u8>) { let keybinds = &self.config.keybinds; - for action in Keybinds::key_to_actions(&key, raw_bytes, &self.mode, keybinds) { - let should_exit = self.dispatch_action(action); - if should_exit { - self.should_exit = true; + if self.pasting { + // we're inside a paste block, if we're in a mode that allows sending text to the + // terminal, send all text directly without interpreting it + // otherwise, just discard the input + if self.mode == InputMode::Normal || self.mode == InputMode::Locked { + let action = Action::Write(raw_bytes); + self.dispatch_action(action); + } + } else { + for action in Keybinds::key_to_actions(&key, raw_bytes, &self.mode, keybinds) { + let should_exit = self.dispatch_action(action); + if should_exit { + self.should_exit = true; + } } } } @@ -119,7 +137,8 @@ impl InputHandler { | Action::GoToNextTab | Action::GoToPreviousTab | Action::CloseTab - | Action::GoToTab(_) => { + | Action::GoToTab(_) + | Action::MoveFocusOrTab(_) => { self.command_is_executing.blocking_input_thread(); self.os_input .send_to_server(ServerInstruction::Action(action)); @@ -146,7 +165,11 @@ impl InputHandler { /// Creates a [`Help`] struct indicating the current [`InputMode`] and its keybinds /// (as pairs of [`String`]s). // TODO this should probably be automatically generated in some way -pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { +pub fn get_mode_info( + mode: InputMode, + palette: Palette, + capabilities: PluginCapabilities, +) -> ModeInfo { let mut keybinds: Vec<(String, String)> = vec![]; match mode { InputMode::Normal | InputMode::Locked => {} @@ -160,7 +183,6 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { 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(("s".to_string(), "Sync".to_string())); keybinds.push(("f".to_string(), "Fullscreen".to_string())); } InputMode::Tab => { @@ -168,6 +190,7 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { keybinds.push(("n".to_string(), "New".to_string())); keybinds.push(("x".to_string(), "Close".to_string())); keybinds.push(("r".to_string(), "Rename".to_string())); + keybinds.push(("s".to_string(), "Sync".to_string())); } InputMode::Scroll => { keybinds.push(("↓↑".to_string(), "Scroll".to_string())); @@ -181,6 +204,7 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { mode, keybinds, palette, + capabilities, } } |
