Remove set-mode char event

Use generic shell commands instead.  This keeps us honest.

No functional change expected.
This commit is contained in:
Johannes Altmanninger 2024-03-30 12:10:23 +01:00
parent 20bbdb68fa
commit aa40c3fb7e
3 changed files with 11 additions and 38 deletions

View File

@ -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 => {

View File

@ -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,

View File

@ -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();