mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-17 07:32:45 +08:00
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 b815319607
.
This commit is contained in:
parent
d855d1a2e6
commit
a126d2aeba
18
src/input.rs
18
src/input.rs
|
@ -5,7 +5,6 @@ use crate::event;
|
|||
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 @@ impl EventQueuePeeker<'_> {
|
|||
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 @@ impl EventQueuePeeker<'_> {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::env::{EnvStack, Environment};
|
|||
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 @@ impl 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 @@ pub trait InputEventQueuer {
|
|||
Some(key)
|
||||
}
|
||||
|
||||
fn readch_timed_esc(&mut self, style: &KeyNameStyle) -> Result<CharEvent, bool> {
|
||||
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<CharEvent> {
|
||||
self.readch_timed(WAIT_ON_ESCAPE_MS.load(Ordering::Relaxed))
|
||||
.ok_or(true) // Timed out
|
||||
}
|
||||
|
||||
fn readch_timed_sequence_key(&mut self) -> Option<CharEvent> {
|
||||
|
|
Loading…
Reference in New Issue
Block a user