From aa40c3fb7ed60da0818c2dace0c63d62672663c6 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 30 Mar 2024 12:10:23 +0100 Subject: [PATCH] Remove set-mode char event Use generic shell commands instead. This keeps us honest. No functional change expected. --- src/input.rs | 25 +++++++++---------------- src/input_common.rs | 20 +------------------- src/reader.rs | 4 +--- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/input.rs b/src/input.rs index 270ddad08..89cd6c029 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,6 +1,6 @@ -use crate::common::{get_by_sorted_name, shell_modes, str2wcstring, Named}; +use crate::common::{escape, get_by_sorted_name, shell_modes, str2wcstring, Named}; use crate::curses; -use crate::env::{EnvMode, Environment, CURSES_INITIALIZED}; +use crate::env::{Environment, CURSES_INITIALIZED}; use crate::event; use crate::flog::FLOG; use crate::input_common::{ @@ -249,17 +249,6 @@ fn input_get_bind_mode(vars: &dyn Environment) -> WString { } } -/// Set the current bind mode. -pub fn input_set_bind_mode(parser: &Parser, bm: &wstr) { - // Only set this if it differs to not execute variable handlers all the time. - // modes may not be empty - empty is a sentinel value meaning to not change the mode - assert!(!bm.is_empty()); - if input_get_bind_mode(parser.vars()) != bm { - // Must send events here - see #6653. - parser.set_var_and_fire(FISH_BIND_MODE_VAR, EnvMode::GLOBAL, vec![bm.to_owned()]); - } -} - /// Returns the arity of a given input function. fn input_function_arity(function: ReadlineCmd) -> usize { match function { @@ -510,8 +499,12 @@ impl Inputter { self.push_front(evt); } // Missing bind mode indicates to not reset the mode (#2871) - if let Some(sets_mode) = m.sets_mode.as_ref() { - self.push_front(CharEvent::from_set_mode(sets_mode.clone())); + if let Some(mode) = m.sets_mode.as_ref() { + self.push_front(CharEvent::from_command(sprintf!( + "set --global %s %s", + FISH_BIND_MODE_VAR, + escape(mode) + ))); } } @@ -892,7 +885,7 @@ impl Inputter { return evt; } }, - CharEventType::Command(_) | CharEventType::SetMode(_) => { + CharEventType::Command(_) => { return evt; } CharEventType::Eof => { diff --git a/src/input_common.rs b/src/input_common.rs index cd97c6231..33ad4b3b3 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -129,9 +129,6 @@ pub enum CharEventType { /// A shell command. Command(WString), - /// A request to change the input mapping mode. - SetMode(WString), - /// end-of-file was reached. Eof, @@ -173,7 +170,7 @@ impl CharEvent { pub fn is_readline_or_command(&self) -> bool { matches!( self.evt, - CharEventType::Readline(_) | CharEventType::Command(_) | CharEventType::SetMode(_) + CharEventType::Readline(_) | CharEventType::Command(_) ) } @@ -206,13 +203,6 @@ impl CharEvent { } } - pub fn get_mode(&self) -> Option<&wstr> { - match &self.evt { - CharEventType::SetMode(m) => Some(m), - _ => None, - } - } - pub fn from_char(c: char) -> CharEvent { CharEvent { evt: CharEventType::Char(c), @@ -241,14 +231,6 @@ impl CharEvent { } } - pub fn from_set_mode(mode: WString) -> CharEvent { - CharEvent { - evt: CharEventType::SetMode(mode), - input_style: CharInputStyle::Normal, - seq: WString::new(), - } - } - pub fn from_check_exit() -> CharEvent { CharEvent { evt: CharEventType::CheckExit, diff --git a/src/reader.rs b/src/reader.rs index aab8c1a1b..e1d3fa0cb 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -66,8 +66,8 @@ use crate::history::{ history_session_id, in_private_mode, History, HistorySearch, PersistenceMode, SearchDirection, SearchType, }; +use crate::input::init_input; use crate::input::Inputter; -use crate::input::{init_input, input_set_bind_mode}; use crate::input_common::{CharEvent, CharInputStyle, ReadlineCmd}; use crate::io::IoChain; use crate::kill::{kill_add, kill_replace, kill_yank, kill_yank_rotate}; @@ -1882,8 +1882,6 @@ impl ReaderData { rls.last_cmd = Some(readline_cmd); } else if let Some(command) = event_needing_handling.get_command() { zelf.run_input_command_scripts(command); - } else if let Some(mode) = event_needing_handling.get_mode() { - input_set_bind_mode(zelf.parser(), mode); } else { // Ordinary char. let c = event_needing_handling.get_char();