From 67311ebda73ec8471dd32fc5d274e57db1470b4b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 26 Jun 2022 16:54:05 -0700 Subject: [PATCH] fix `winget list` causes toast notification spam https://github.com/wez/wezterm/pull/1939 caused the ConEMU OSC 9 escapes to be interpreted as toast notification escapes. This commit restores the nature of the `single_string` macro to validate the number of OSC parameters by default, but allow the string combining just for the unambiguous title related OSC codes. refs: https://github.com/wez/wezterm/issues/2185 --- termwiz/src/escape/osc.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/termwiz/src/escape/osc.rs b/termwiz/src/escape/osc.rs index 6a90dd5b7..04f56fc32 100644 --- a/termwiz/src/escape/osc.rs +++ b/termwiz/src/escape/osc.rs @@ -273,6 +273,16 @@ impl OperatingSystemCommand { .ok_or_else(|| format!("unknown code"))?; macro_rules! single_string { + ($variant:ident) => {{ + if osc.len() != 2 { + bail!("wrong param count"); + } + let s = String::from_utf8(osc[1].to_vec())?; + Ok(OperatingSystemCommand::$variant(s)) + }}; + } + + macro_rules! single_title_string { ($variant:ident) => {{ if osc.len() < 2 { bail!("wrong param count"); @@ -288,13 +298,13 @@ impl OperatingSystemCommand { use self::OperatingSystemCommandCode::*; match osc_code { - SetIconNameAndWindowTitle => single_string!(SetIconNameAndWindowTitle), - SetWindowTitle => single_string!(SetWindowTitle), + SetIconNameAndWindowTitle => single_title_string!(SetIconNameAndWindowTitle), + SetWindowTitle => single_title_string!(SetWindowTitle), SetWindowTitleSun => Ok(OperatingSystemCommand::SetWindowTitleSun( p1str[1..].to_owned(), )), - SetIconName => single_string!(SetIconName), + SetIconName => single_title_string!(SetIconName), SetIconNameSun => Ok(OperatingSystemCommand::SetIconNameSun( p1str[1..].to_owned(), )),