Don't send kitty kbd protocol probe until ECHO is disabled

With tmux 3.0 (from 2019) inside SSH, the CSI 5n response is echoed.
I guess with all other terminals we were just lucky.  Move it to
right after where we disable ECHO I guess.

In general, asynchronous requests create a lot of potential for error,
we should try to get away from them.
This commit is contained in:
Johannes Altmanninger 2025-01-05 17:53:09 +01:00
parent 109ef88831
commit 10f1f21a4f
3 changed files with 14 additions and 5 deletions

View file

@ -9,19 +9,19 @@
use std::{ops::ControlFlow, os::unix::prelude::OsStrExt};
use libc::{STDIN_FILENO, TCSANOW, VEOF, VINTR};
use libc::{STDIN_FILENO, STDOUT_FILENO, TCSANOW, VEOF, VINTR};
#[allow(unused_imports)]
use fish::future::IsSomeAnd;
use fish::{
builtins::shared::BUILTIN_ERR_UNKNOWN,
common::{shell_modes, str2wcstring, PROGRAM_NAME},
common::{shell_modes, str2wcstring, write_loop, PROGRAM_NAME},
env::env_init,
eprintf, fprintf,
input::input_terminfo_get_name,
input_common::{
terminal_protocol_hacks, terminal_protocols_enable_ifn, CharEvent, InputEventQueue,
InputEventQueuer,
InputEventQueuer, KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY,
},
key::{char_to_symbol, Key},
panic::panic_handler,
@ -137,6 +137,7 @@ fn setup_and_process_keys(continuous_mode: bool, verbose: bool) -> i32 {
unsafe { libc::tcsetattr(STDIN_FILENO, TCSANOW, &*shell_modes()) };
terminal_protocol_hacks();
let _ = write_loop(&STDOUT_FILENO, KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY);
if continuous_mode {
eprintf!("\n");

View file

@ -451,6 +451,8 @@ macro_rules! kitty_progressive_enhancements {
};
}
pub const KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY: &[u8] = b"\x1b[?u\x1b[5n";
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);
@ -468,8 +470,6 @@ pub fn terminal_protocol_hacks() {
version < (3, 5, 6)
}),
);
// Request kitty progressive enhancement value and primary device attribute.
let _ = write_loop(&STDOUT_FILENO, b"\x1b[?u\x1b[5n");
}
fn parse_version(version: &wstr) -> Option<(i64, i64, i64)> {

View file

@ -82,6 +82,7 @@ use crate::input_common::ImplicitEvent;
use crate::input_common::InputEventQueuer;
use crate::input_common::WaitingForCursorPosition;
use crate::input_common::IN_MIDNIGHT_COMMANDER_PRE_CSI_U;
use crate::input_common::KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY;
use crate::input_common::{
terminal_protocol_hacks, terminal_protocols_enable_ifn, CharEvent, CharInputStyle, InputData,
ReadlineCmd,
@ -2083,6 +2084,13 @@ impl<'a> Reader<'a> {
}
}
static queried: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
if !queried.load() {
queried.store(true);
// Query for kitty keyboard protocol support.
let _ = write_loop(&STDOUT_FILENO, KITTY_PROGRESSIVE_ENHANCEMENTS_QUERY);
}
// HACK: Don't abandon line for the first prompt, because
// if we're started with the terminal it might not have settled,
// so the width is quite likely to be in flight.