From bd9fee417b0a3452db242c5632f9aeb2f46719a5 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 8 Oct 2024 23:34:39 +0200 Subject: [PATCH] Use kitty keyboard protocol again for recent Midnight Commander See https://midnight-commander.org/ticket/4597 --- src/input_common.rs | 5 ++--- src/reader.rs | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/input_common.rs b/src/input_common.rs index f75ae65e9..91707f31e 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -431,13 +431,12 @@ pub fn update_wait_on_sequence_key_ms(vars: &EnvStack) { static TERMINAL_PROTOCOLS: AtomicBool = AtomicBool::new(false); static IS_TMUX: RelaxedAtomicBool = RelaxedAtomicBool::new(false); -static IN_MIDNIGHT_COMMANDER: 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); pub fn terminal_protocol_hacks() { use std::env::var_os; IS_TMUX.store(var_os("TMUX").is_some()); - IN_MIDNIGHT_COMMANDER.store(var_os("MC_TMPDIR").is_some()); IN_ITERM_PRE_CSI_U.store( var_os("LC_TERMINAL").is_some_and(|term| term.as_os_str().as_bytes() == b"iTerm2") && var_os("LC_TERMINAL_VERSION").is_some_and(|version| { @@ -474,7 +473,7 @@ pub fn terminal_protocols_enable_ifn() { return; } TERMINAL_PROTOCOLS.store(true, Ordering::Release); - let sequences = if IN_MIDNIGHT_COMMANDER.load() { + let sequences = if IN_MIDNIGHT_COMMANDER_PRE_CSI_U.load() { "\x1b[?2004h" } else if IN_ITERM_PRE_CSI_U.load() { concat!("\x1b[?2004h", "\x1b[>4;1m", "\x1b[>5u", "\x1b=",) diff --git a/src/reader.rs b/src/reader.rs index a9b8e0130..d039f73dd 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -75,6 +75,7 @@ use crate::history::{ SearchType, }; use crate::input::init_input; +use crate::input_common::IN_MIDNIGHT_COMMANDER_PRE_CSI_U; use crate::input_common::{ terminal_protocol_hacks, terminal_protocols_enable_ifn, CharEvent, CharInputStyle, InputData, ReadlineCmd, @@ -3976,6 +3977,8 @@ fn reader_interactive_init(parser: &Parser) { .set_one(L!("_"), EnvMode::GLOBAL, L!("fish").to_owned()); terminal_protocol_hacks(); + IN_MIDNIGHT_COMMANDER_PRE_CSI_U + .store(parser.vars().get_unless_empty(L!("__mc_csi_u")).is_none()); } /// Destroy data for interactive use.