Refresh TTY timestamps also in some rare cases

As mentioned in
https://github.com/fish-shell/fish-shell/pull/11045#discussion_r1915994998,
we need to refresh TTY timestamps to avoid timing-based issues.

For some context see

	git log --grep='[Rr]efresh.* TTY'

Make things more consistent again. I don't know if all of these are
absolutely necessary, hoping to find out later (and consolidate this
logic in outputter).
This commit is contained in:
Johannes Altmanninger 2025-01-15 07:58:48 +01:00
parent 2e025cfd76
commit 081c3282b7
2 changed files with 27 additions and 12 deletions

View File

@ -198,6 +198,8 @@ pub enum ImplicitEvent {
ScrollbackPushContinuation(usize),
/// The Synchronized Output feature is supported by the terminal.
SynchronizedOutputSupported,
/// Terminal reports support for the kitty keyboard protocol.
KittyKeyboardSupported,
}
#[derive(Debug, Clone)]
@ -458,6 +460,14 @@ macro_rules! kitty_progressive_enhancements {
pub const KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY: &[u8] = b"\x1b[?u";
pub(crate) fn enable_kitty_progressive_enhancements() -> bool {
if IN_MIDNIGHT_COMMANDER_PRE_CSI_U.load() || IN_ITERM_PRE_CSI_U.load() {
return false;
}
let _ = write_loop(&STDOUT_FILENO, kitty_progressive_enhancements!().as_bytes());
true
}
static IS_TMUX: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
pub static IN_MIDNIGHT_COMMANDER_PRE_CSI_U: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
static IN_ITERM_PRE_CSI_U: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
@ -1135,12 +1145,7 @@ pub trait InputEventQueuer {
"Received kitty progressive enhancement flags, marking as supported"
);
KITTY_KEYBOARD_SUPPORTED.store(true);
if !IN_MIDNIGHT_COMMANDER_PRE_CSI_U.load() && !IN_ITERM_PRE_CSI_U.load() {
let _ = write_loop(
&STDOUT_FILENO,
kitty_progressive_enhancements!().as_bytes(),
);
}
self.push_front(CharEvent::Implicit(ImplicitEvent::KittyKeyboardSupported));
return None;
}

View File

@ -79,6 +79,7 @@ use crate::history::{
SearchType,
};
use crate::input::init_input;
use crate::input_common::enable_kitty_progressive_enhancements;
use crate::input_common::CursorPositionBlockingWait;
use crate::input_common::CursorPositionWait;
use crate::input_common::ImplicitEvent;
@ -2448,6 +2449,7 @@ impl<'a> Reader<'a> {
Outputter::stdoutput()
.borrow_mut()
.write_wstr(L!("\x1B[?1000l"));
self.save_screen_state();
}
ImplicitEvent::MouseLeftClickContinuation(cursor, click_position) => {
self.mouse_left_click(cursor, click_position);
@ -2458,7 +2460,14 @@ impl<'a> Reader<'a> {
self.stop_waiting_for_cursor_position();
}
ImplicitEvent::SynchronizedOutputSupported => {
synchronized_supported();
if query_capabilities_via_dcs() {
self.save_screen_state();
}
}
ImplicitEvent::KittyKeyboardSupported => {
if enable_kitty_progressive_enhancements() {
self.save_screen_state();
}
}
},
}
@ -2478,10 +2487,10 @@ fn xtgettcap(out: &mut impl Write, cap: &str) {
let _ = write!(out, "\x1bP+q{}\x1b\\", DisplayAsHex(cap));
}
fn synchronized_supported() {
fn query_capabilities_via_dcs() -> bool {
static QUERIED: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
if QUERIED.load() {
return;
return false;
}
QUERIED.store(true);
let mut out = Outputter::stdoutput().borrow_mut();
@ -2493,6 +2502,7 @@ fn synchronized_supported() {
let _ = out.write(b"\x1b[?1049l"); // disable alternative screen buffer
let _ = out.write(b"\x1b[?2026l"); // end synchronized update
out.end_buffering();
true
}
impl<'a> Reader<'a> {
@ -3726,9 +3736,9 @@ impl<'a> Reader<'a> {
CursorPositionWait::Blocking(_) => {
// TODO: re-queue it I guess.
FLOG!(
reader,
"Ignoring scrollback-push received while still waiting for Cursor Position Report"
);
reader,
"Ignoring scrollback-push received while still waiting for Cursor Position Report"
);
}
}
}