diff --git a/src/bin/fish_key_reader.rs b/src/bin/fish_key_reader.rs index 7412b27fc..c7c9cb695 100644 --- a/src/bin/fish_key_reader.rs +++ b/src/bin/fish_key_reader.rs @@ -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"); diff --git a/src/input_common.rs b/src/input_common.rs index ed05959c8..15e7e7258 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -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)> { diff --git a/src/reader.rs b/src/reader.rs index 8716099ce..e7f903026 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -82,6 +82,7 @@ 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 @@ fn readline(&mut self, nchars: Option) -> Option { } } + 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.