From 15cd74a3bb8287a0cb9eb0fd1b4aa812dd1210f0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 10 Apr 2024 22:33:40 +0200 Subject: [PATCH] Fix fish_escape_delay_ms for terminals that send CSI 27 u See the parent commit for some context. Turns out that 8bf8b10f6 (Extended & human-friendly keys, 2024-03-30) broke this for terminals that speak CSI u. This is pretty complex, probably not worth it. --- src/input.rs | 18 ++++++++++++------ src/input_common.rs | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/input.rs b/src/input.rs index df65559f0..147ce847c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -5,8 +5,9 @@ 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}; +use crate::key::{self, canonicalize_raw_escapes, ctrl, Key, Modifiers}; use crate::parser::Parser; use crate::proc::job_reap; use crate::reader::{ @@ -667,6 +668,15 @@ fn next_is_char(&mut self, key: Key, escaped: bool) -> bool { let Some(kevt) = evt.get_key() else { return false; }; + if WAIT_ON_ESCAPE_MS.load(Ordering::Relaxed) != 0 + && kevt.key == Key::from_raw(key::Escape) + && key.modifiers == Modifiers::ALT + { + self.idx += 1; + self.subidx = 0; + FLOG!(reader, "matched delayed escape prefix in alt sequence"); + return self.next_is_char(Key::from_raw(key.codepoint), true); + } if self.subidx == 0 && kevt.key == key { self.idx += 1; return true; @@ -684,11 +694,7 @@ fn next_is_char(&mut self, key: Key, escaped: bool) -> bool { // FLOG!(reader, "matched legacy sequence for", key); return true; } - if key.modifiers.alt - && !key.modifiers.ctrl - && !key.modifiers.shift - && seq_char == '\x1b' - { + if key.modifiers == Modifiers::ALT && seq_char == '\x1b' { if self.subidx + 1 == actual_seq.len() { self.idx += 1; self.subidx = 0; diff --git a/src/input_common.rs b/src/input_common.rs index 4574e8690..1e9007b08 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -279,7 +279,7 @@ 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. -static WAIT_ON_ESCAPE_MS: AtomicUsize = AtomicUsize::new(0); +pub(crate) static WAIT_ON_ESCAPE_MS: AtomicUsize = AtomicUsize::new(0); const WAIT_ON_SEQUENCE_KEY_INFINITE: usize = usize::MAX; static WAIT_ON_SEQUENCE_KEY_MS: AtomicUsize = AtomicUsize::new(WAIT_ON_SEQUENCE_KEY_INFINITE);