From ccf9fc141bdd1f606bf190a3bf04cb3c01fe688e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 31 May 2020 15:45:25 -0700 Subject: [PATCH] wezterm: fixup DECKPAM/DECANM/DECCKM interaction We were treating DECCKM as the sole thing to enable application cursor reporting, but looking closely at the docs, that mode only takes effect when both DECANM (Vt52 emulation mode) AND DECKPAM (application keypad mode) are both active. neovim enables DECCKM and DECKPAM but not DECANM. refs: https://github.com/wez/wezterm/issues/203 --- term/src/terminalstate.rs | 16 +++++++++++++++- termwiz/src/escape/csi.rs | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 575c4dc5f..add87bc2b 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -202,6 +202,8 @@ pub struct TerminalState { /// keys. The code in key_down() is responsible for interpreting this. application_cursor_keys: bool, + dec_ansi_mode: bool, + /// When set, modifies the sequence of bytes sent for keys /// in the numeric keypad portion of the keyboard. application_keypad: bool, @@ -303,6 +305,7 @@ impl TerminalState { dec_origin_mode: false, insert: false, application_cursor_keys: false, + dec_ansi_mode: false, application_keypad: false, bracketed_paste: false, sgr_mouse: false, @@ -640,7 +643,11 @@ impl TerminalState { _ => unreachable!(), }; - let csi_or_ss3 = if force_app || self.application_cursor_keys { + let csi_or_ss3 = if force_app + || (self.application_cursor_keys + && self.dec_ansi_mode + && self.application_keypad) + { // Use SS3 in application mode "\x1bO" } else { @@ -1149,6 +1156,13 @@ impl TerminalState { self.application_cursor_keys = false; } + Mode::SetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::DecAnsiMode)) => { + self.dec_ansi_mode = true; + } + Mode::ResetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::DecAnsiMode)) => { + self.dec_ansi_mode = false; + } + Mode::SetDecPrivateMode(DecPrivateMode::Code(DecPrivateModeCode::ShowCursor)) => { self.cursor_visible = true; } diff --git a/termwiz/src/escape/csi.rs b/termwiz/src/escape/csi.rs index f13829494..8ba51d3ff 100644 --- a/termwiz/src/escape/csi.rs +++ b/termwiz/src/escape/csi.rs @@ -458,7 +458,17 @@ pub enum DecPrivateMode { #[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)] pub enum DecPrivateModeCode { + /// https://vt100.net/docs/vt510-rm/DECCKM.html + /// This mode is only effective when the terminal is in keypad application mode (see DECKPAM) + /// and the ANSI/VT52 mode (DECANM) is set (see DECANM). Under these conditions, if the cursor + /// key mode is reset, the four cursor function keys will send ANSI cursor control commands. If + /// cursor key mode is set, the four cursor function keys will send application functions. ApplicationCursorKeys = 1, + + /// https://vt100.net/docs/vt510-rm/DECANM.html + /// Behave like a vt52 + DecAnsiMode = 2, + /// https://vt100.net/docs/vt510-rm/DECCOLM.html Select132Columns = 3, /// https://vt100.net/docs/vt510-rm/DECSCLM.html