From 42e2775f3643bb35b7011b4dfdee935b561dbc18 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 1 Jun 2020 18:59:18 -0700 Subject: [PATCH] wezterm: more fun with SS3 vs CSI and cursor key encoding I noticed that we still weren't quite right. I think the net change is really just that we must force the use of the CSI representation when using CTRL/SHIFT modifiers. refs: https://github.com/wez/wezterm/issues/203 --- term/src/lib.rs | 3 ++- term/src/terminalstate.rs | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/term/src/lib.rs b/term/src/lib.rs index 04dd2386c..3d5599c7d 100644 --- a/term/src/lib.rs +++ b/term/src/lib.rs @@ -107,7 +107,8 @@ mod test; /// certain feature sets. pub const DEVICE_IDENT: &[u8] = b"\x1b[?6c"; -pub const CSI: &[u8] = b"\x1b["; +pub const CSI: &str = "\x1b["; pub const OSC: &[u8] = b"\x1b]"; pub const ST: &[u8] = b"\x1b\\"; +pub const SS3: &str = "\x1bO"; pub const DCS: &[u8] = b"\x1bP"; diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index add87bc2b..d1595c41d 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -644,19 +644,22 @@ impl TerminalState { }; let csi_or_ss3 = if force_app - || (self.application_cursor_keys - && self.dec_ansi_mode - && self.application_keypad) - { + || ( + self.application_cursor_keys + // Strict reading of DECCKM suggests that application_cursor_keys + // only applies when DECANM and DECKPAM are active, but that seems + // to break unmodified cursor keys in vim + /* && self.dec_ansi_mode && self.application_keypad */ + ) { // Use SS3 in application mode - "\x1bO" + SS3 } else { // otherwise use regular CSI - "\x1b[" + CSI }; if mods.contains(KeyModifiers::SHIFT) || mods.contains(KeyModifiers::CTRL) { - write!(buf, "{}1;{}{}", csi_or_ss3, 1 + encode_modifiers(mods), c)?; + write!(buf, "{}1;{}{}", CSI, 1 + encode_modifiers(mods), c)?; } else { if mods.contains(KeyModifiers::ALT) { buf.push(0x1b as char);