Hack to make alt-{left,right} work again in iTerm2

iTerm2 deviates from protocol, so back out c3c832761 (Stop using stack for
kitty progressive enhancement, 2024-08-03) in that case.

Note that we use several ways of detecting iTerm2 (ITERM_PROFILE,
TERM_PROGRAM=iTerm.app, ITERM_SESSION_ID).
LC_TERMINAL seems superior because it works over ssh.

This new one should hopefully go away eventually.
This commit is contained in:
Johannes Altmanninger 2024-08-06 10:32:41 +02:00
parent 5acac84df9
commit 7cfc6297bc
2 changed files with 28 additions and 12 deletions

View File

@ -435,6 +435,7 @@ static TERMINAL_PROTOCOLS: MainThread<RefCell<Option<TerminalProtocols>>> =
pub(crate) static IS_TMUX: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
pub(crate) static IN_MIDNIGHT_COMMANDER: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
pub(crate) static IN_ITERM: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
pub fn terminal_protocols_enable_ifn() {
if IN_MIDNIGHT_COMMANDER.load() {
@ -461,12 +462,16 @@ struct TerminalProtocols {}
impl TerminalProtocols {
fn new() -> Self {
let sequences = concat!(
"\x1b[?2004h", // Bracketed paste
"\x1b[>4;1m", // XTerm's modifyOtherKeys
"\x1b[=5u", // CSI u with kitty progressive enhancement
"\x1b=", // set application keypad mode, so the keypad keys send unique codes
);
let sequences = if IN_ITERM.load() {
concat!("\x1b[?2004h", "\x1b[>4;1m", "\x1b[>5u", "\x1b=",)
} else {
concat!(
"\x1b[?2004h", // Bracketed paste
"\x1b[>4;1m", // XTerm's modifyOtherKeys
"\x1b[=5u", // CSI u with kitty progressive enhancement
"\x1b=", // set application keypad mode, so the keypad keys send unique codes
)
};
FLOG!(
term_protocols,
format!(
@ -485,12 +490,16 @@ impl TerminalProtocols {
impl Drop for TerminalProtocols {
fn drop(&mut self) {
let sequences = concat!(
"\x1b[?2004l", // Bracketed paste
"\x1b[>4;0m", // XTerm's modifyOtherKeys
"\x1b[=0u", // CSI u with kitty progressive enhancement
"\x1b>", // application keypad mode
);
let sequences = if IN_ITERM.load() {
concat!("\x1b[?2004l", "\x1b[>4;0m", "\x1b[<1u", "\x1b>",)
} else {
concat!(
"\x1b[?2004l", // Bracketed paste
"\x1b[>4;0m", // XTerm's modifyOtherKeys
"\x1b[=0u", // CSI u with kitty progressive enhancement
"\x1b>", // application keypad mode
)
};
FLOG!(
term_protocols,
format!(

View File

@ -70,6 +70,7 @@ use crate::history::{
SearchType,
};
use crate::input::init_input;
use crate::input_common::IN_ITERM;
use crate::input_common::IN_MIDNIGHT_COMMANDER;
use crate::input_common::{
terminal_protocols_disable_ifn, terminal_protocols_enable_ifn, CharEvent, CharInputStyle,
@ -3851,6 +3852,12 @@ fn reader_interactive_init(parser: &Parser) {
IS_TMUX.store(parser.vars().get_unless_empty(L!("TMUX")).is_some());
IN_MIDNIGHT_COMMANDER.store(parser.vars().get_unless_empty(L!("MC_TMPDIR")).is_some());
IN_ITERM.store(
parser
.vars()
.get(L!("LC_TERMINAL"))
.is_some_and(|term| term.as_list() == &[L!("iTerm2")]),
);
}
/// Destroy data for interactive use.