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