From 6bd6d844caa0534e220d3515cf2f49daa9f56bf2 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 27 Mar 2022 19:34:12 -0700 Subject: [PATCH] term: fix XTGETTCAP response refs: https://github.com/wez/wezterm/issues/1781 refs: https://github.com/dankamongmen/notcurses/issues/2637 --- docs/changelog.md | 1 + term/src/terminalstate/mod.rs | 38 ++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 5e7b320e6..7137a2cc8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -31,6 +31,7 @@ As features stabilize some brief notes about them will accumulate here. * On Windows, touchpad scrolling was janky. Many thanks to [@davidrios](https://github.coim/davidrios)! [#1773](https://github.com/wez/wezterm/pull/1773) [#1725](https://github.com/wez/wezterm/pull/1725) [#949](https://github.com/wez/wezterm/pull/949) * X11: workaround i3-gaps not sending initial CONFIGURE_NOTIFY or FOCUS events, leading to weird initial window size and broken focus status. [#1710](https://github.com/wez/wezterm/issues/1710) [#1757](https://github.com/wez/wezterm/issues/1757) * Hyperlink rules with more captures than replacements could panic wezterm when text matched. [#1780](https://github.com/wez/wezterm/issues/1780) +* Malformed XTGETTCAP response. [#1781](https://github.com/wez/wezterm/issues/1781) ### 20220319-142410-0fcdea07 diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index ef5931260..1d73e278c 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -1097,13 +1097,12 @@ impl TerminalState { } /// + /// XTGETTCAP fn xt_get_tcap(&mut self, names: Vec) { - let mut res = "\x1bP".to_string(); + let mut res = String::new(); - for (i, name) in names.iter().enumerate() { - if i > 0 { - res.push(';'); - } + for name in &names { + res.push_str("\x1bP"); let encoded_name = hex::encode_upper(&name); match name.as_str() { @@ -1120,14 +1119,16 @@ impl TerminalState { res.push_str("1+r"); res.push_str(&encoded_name); res.push('='); - res.push_str(&256.to_string()); + let encoded_val = hex::encode_upper("256"); + res.push_str(&encoded_val); } "RGB" => { res.push_str("1+r"); res.push_str(&encoded_name); res.push('='); - res.push_str("8/8/8"); + let encoded_val = hex::encode_upper("8/8/8"); + res.push_str(&encoded_val); } _ => { @@ -1135,15 +1136,12 @@ impl TerminalState { res.push_str("1+r"); res.push_str(&encoded_name); res.push('='); - match value { - Value::True => res.push('1'), - Value::Number(n) => res.push_str(&n.to_string()), - Value::String(s) => { - for &b in s { - res.push(b as char); - } - } - } + let value = match value { + Value::True => hex::encode_upper("1"), + Value::Number(n) => hex::encode_upper(&n.to_string()), + Value::String(s) => hex::encode_upper(s), + }; + res.push_str(&value); } else { log::trace!("xt_get_tcap: unknown name {}", name); res.push_str("0+r"); @@ -1151,10 +1149,14 @@ impl TerminalState { } } } + res.push_str("\x1b\\"); } - res.push_str("\x1b\\"); - log::trace!("responding with {}", res.escape_debug()); + log::trace!( + "XTGETTCAP {:?} responding with {}", + names, + res.escape_debug() + ); self.writer.write_all(res.as_bytes()).ok(); }