Make CharEvent a native enum

This commit is contained in:
Johannes Altmanninger
2024-03-30 13:01:57 +01:00
parent aa40c3fb7e
commit d0cdb142de
5 changed files with 161 additions and 157 deletions

View File

@@ -4,7 +4,7 @@
use crate::event;
use crate::flog::FLOG;
use crate::input_common::{
CharEvent, CharEventType, CharInputStyle, InputEventQueuer, ReadlineCmd, R_END_INPUT_FUNCTIONS,
CharEvent, CharInputStyle, InputEventQueuer, ReadlineCmd, R_END_INPUT_FUNCTIONS,
};
use crate::parser::Parser;
use crate::proc::job_reap;
@@ -464,8 +464,8 @@ fn function_push_args(&mut self, code: ReadlineCmd) {
let arg: char;
loop {
let evt = self.readch();
if evt.is_char() {
arg = evt.get_char();
if let Some(c) = evt.get_char() {
arg = c;
break;
}
skipped.push(evt);
@@ -494,13 +494,13 @@ fn mapping_execute(&mut self, m: &InputMapping) {
self.function_push_args(code);
CharEvent::from_readline_seq(code, m.seq.clone())
}
None => CharEvent::from_command(cmd.clone()),
None => CharEvent::Command(cmd.clone()),
};
self.push_front(evt);
}
// Missing bind mode indicates to not reset the mode (#2871)
if let Some(mode) = m.sets_mode.as_ref() {
self.push_front(CharEvent::from_command(sprintf!(
self.push_front(CharEvent::Command(sprintf!(
"set --global %s %s",
FISH_BIND_MODE_VAR,
escape(mode)
@@ -601,7 +601,7 @@ fn next_is_char(&mut self, c: char, escaped: bool) -> bool {
}
// Now we have peeked far enough; check the event.
// If it matches the char, then increment the index.
if self.peeked[self.idx].maybe_char() == Some(c) {
if self.peeked[self.idx].get_char() == Some(c) {
self.idx += 1;
return true;
}
@@ -656,7 +656,7 @@ fn have_mouse_tracking_csi(peeker: &mut EventQueuePeeker) -> bool {
return false;
}
let mut next = peeker.next().maybe_char();
let mut next = peeker.next().get_char();
let length;
if next == Some('M') {
// Generic X10 or modified VT200 sequence. It doesn't matter which, they're both 6 chars
@@ -667,7 +667,7 @@ fn have_mouse_tracking_csi(peeker: &mut EventQueuePeeker) -> bool {
// Extended (SGR/1006) mouse reporting mode, with semicolon-separated parameters for button
// code, Px, and Py, ending with 'M' for button press or 'm' for button release.
loop {
next = peeker.next().maybe_char();
next = peeker.next().get_char();
if next == Some('M') || next == Some('m') {
// However much we've read, we've consumed the CSI in its entirety.
length = peeker.len();
@@ -854,29 +854,29 @@ pub fn read_char(&mut self) -> CharEvent {
// Search for sequence in mapping tables.
loop {
let evt = self.readch();
match evt.evt {
CharEventType::Readline(cmd) => match cmd {
match evt {
CharEvent::Readline(ref readline_event) => match readline_event.cmd {
ReadlineCmd::SelfInsert | ReadlineCmd::SelfInsertNotFirst => {
// Typically self-insert is generated by the generic (empty) binding.
// However if it is generated by a real sequence, then insert that sequence.
let seq = evt.seq.chars().map(CharEvent::from_char);
let seq = readline_event.seq.chars().map(CharEvent::from_char);
self.insert_front(seq);
// Issue #1595: ensure we only insert characters, not readline functions. The
// common case is that this will be empty.
let mut res = self.read_characters_no_readline();
// Hackish: mark the input style.
res.input_style = if cmd == ReadlineCmd::SelfInsertNotFirst {
CharInputStyle::NotFirst
} else {
CharInputStyle::Normal
};
if readline_event.cmd == ReadlineCmd::SelfInsertNotFirst {
if let CharEvent::Char(cevt) = &mut res {
cevt.input_style = CharInputStyle::NotFirst;
}
}
return res;
}
ReadlineCmd::FuncAnd | ReadlineCmd::FuncOr => {
// If previous function has bad status, skip all functions that follow us.
if (!self.function_status && cmd == ReadlineCmd::FuncAnd)
|| (self.function_status && cmd == ReadlineCmd::FuncOr)
if (!self.function_status && readline_event.cmd == ReadlineCmd::FuncAnd)
|| (self.function_status && readline_event.cmd == ReadlineCmd::FuncOr)
{
self.drop_leading_readline_events();
}
@@ -885,19 +885,19 @@ pub fn read_char(&mut self) -> CharEvent {
return evt;
}
},
CharEventType::Command(_) => {
CharEvent::Command(_) => {
return evt;
}
CharEventType::Eof => {
CharEvent::Eof => {
// If we have EOF, we need to immediately quit.
// There's no need to go through the input functions.
return evt;
}
CharEventType::CheckExit => {
CharEvent::CheckExit => {
// Allow the reader to check for exit conditions.
return evt;
}
CharEventType::Char(_) => {
CharEvent::Char(ref _cevt) => {
self.push_front(evt);
self.mapping_execute_matching_or_generic();
}