From a126d2aeba5a90e0ad6cba1fa0d740f4c33918b7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 30 Apr 2024 10:28:47 +0200 Subject: [PATCH] Revert "Remove redundant default escape delay" I think given a local terminal running fish on a remote system, we can't assume that an input sequence like \ea is sent all in one packet. (If we could that would be perfect.) Let's readd the default escape delay, to avoid a potential regression, but make it only apply to raw escape bindings like "bind \e123". Treat sequences like "bind escape,1,2,3" like regular sequences, so they can be bound on all terminals. This partially reverts commit b815319607b8df912288ad6f4370adff4c9e750d. --- src/input.rs | 18 ++++++------------ src/input_common.rs | 16 ++++------------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/input.rs b/src/input.rs index dbd19acbd..bd805e513 100644 --- a/src/input.rs +++ b/src/input.rs @@ -5,7 +5,6 @@ use crate::flog::FLOG; use crate::input_common::{ CharEvent, CharInputStyle, InputEventQueuer, ReadlineCmd, R_END_INPUT_FUNCTIONS, - WAIT_ON_ESCAPE_MS, }; use crate::key::{self, canonicalize_raw_escapes, ctrl, Key, Modifiers}; use crate::parser::Parser; @@ -654,12 +653,10 @@ fn next_is_char(&mut self, style: &KeyNameStyle, key: Key, escaped: bool) -> boo if self.idx == self.peeked.len() { let newevt = if escaped { FLOG!(reader, "reading timed escape"); - match self.event_queue.readch_timed_esc(style) { - Ok(evt) => evt, - Err(timed_out) => { - if timed_out { - self.had_timeout = true; - } + match self.event_queue.readch_timed_esc() { + Some(evt) => evt, + None => { + self.had_timeout = true; return false; } } @@ -682,10 +679,7 @@ fn next_is_char(&mut self, style: &KeyNameStyle, key: Key, escaped: bool) -> boo let Some(kevt) = evt.get_key() else { return false; }; - if WAIT_ON_ESCAPE_MS.load(Ordering::Relaxed) != 0 - && kevt.seq == L!("\x1b") - && key.modifiers == Modifiers::ALT - { + if kevt.seq == L!("\x1b") && key.modifiers == Modifiers::ALT { self.idx += 1; self.subidx = 0; FLOG!(reader, "matched delayed escape prefix in alt sequence"); @@ -789,7 +783,7 @@ fn try_peek_sequence(peeker: &mut EventQueuePeeker, style: &KeyNameStyle, seq: & for key in seq { // If we just read an escape, we need to add a timeout for the next char, // to distinguish between the actual escape key and an "alt"-modifier. - let escaped = prev == Key::from_raw(key::Escape); + let escaped = *style != KeyNameStyle::Plain && prev == Key::from_raw(key::Escape); if !peeker.next_is_char(style, *key, escaped) { return false; } diff --git a/src/input_common.rs b/src/input_common.rs index 5324bae25..0c39f3a8e 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -8,7 +8,6 @@ use crate::fd_readable_set::FdReadableSet; use crate::flog::FLOG; use crate::global_safety::RelaxedAtomicBool; -use crate::input::KeyNameStyle; use crate::key::{ self, alt, canonicalize_control_char, canonicalize_keyed_control_char, function_key, shift, Key, Modifiers, @@ -281,7 +280,8 @@ pub fn from_check_exit() -> CharEvent { /// Time in milliseconds to wait for another byte to be available for reading /// after \x1B is read before assuming that escape key was pressed, and not an /// escape sequence. -pub(crate) static WAIT_ON_ESCAPE_MS: AtomicUsize = AtomicUsize::new(0); +const WAIT_ON_ESCAPE_DEFAULT: usize = 30; +static WAIT_ON_ESCAPE_MS: AtomicUsize = AtomicUsize::new(WAIT_ON_ESCAPE_DEFAULT); const WAIT_ON_SEQUENCE_KEY_INFINITE: usize = usize::MAX; static WAIT_ON_SEQUENCE_KEY_MS: AtomicUsize = AtomicUsize::new(WAIT_ON_SEQUENCE_KEY_INFINITE); @@ -384,7 +384,7 @@ fn readb(in_fd: RawFd, blocking: bool) -> ReadbResult { pub fn update_wait_on_escape_ms(vars: &EnvStack) { let fish_escape_delay_ms = vars.get_unless_empty(L!("fish_escape_delay_ms")); let Some(fish_escape_delay_ms) = fish_escape_delay_ms else { - WAIT_ON_ESCAPE_MS.store(0, Ordering::Relaxed); + WAIT_ON_ESCAPE_MS.store(WAIT_ON_ESCAPE_DEFAULT, Ordering::Relaxed); return; }; let fish_escape_delay_ms = fish_escape_delay_ms.as_string(); @@ -1026,16 +1026,8 @@ fn parse_ss3(&mut self, buffer: &mut Vec) -> Option { Some(key) } - fn readch_timed_esc(&mut self, style: &KeyNameStyle) -> Result { - let wait_ms = WAIT_ON_ESCAPE_MS.load(Ordering::Relaxed); - if wait_ms == 0 { - if *style == KeyNameStyle::Plain { - return self.readch_timed_sequence_key().ok_or(true); - } - return Err(false); // Not timed out - } + fn readch_timed_esc(&mut self) -> Option { self.readch_timed(WAIT_ON_ESCAPE_MS.load(Ordering::Relaxed)) - .ok_or(true) // Timed out } fn readch_timed_sequence_key(&mut self) -> Option {