diff --git a/src/tty_handoff.rs b/src/tty_handoff.rs index 1d7a390a0..900abb44a 100644 --- a/src/tty_handoff.rs +++ b/src/tty_handoff.rs @@ -65,7 +65,7 @@ pub enum TtyQuirks { // Running in iTerm2 before 3.5.12, which causes issues when using the kitty keyboard protocol. PreKittyIterm2, // Whether we are running under tmux. - Tmux, + Tmux((u32, u32)), // Whether we are running under WezTerm. Wezterm, } @@ -80,8 +80,8 @@ fn detect(vars: &dyn Environment, xtversion: &wstr) -> Self { PreCsiMidnightCommander } else if get_iterm2_version(xtversion).is_some_and(|v| v < (3, 5, 12)) { PreKittyIterm2 - } else if xtversion.starts_with(L!("tmux ")) { - Tmux + } else if let Some(version) = get_tmux_version(xtversion) { + Tmux(version) } else if xtversion.starts_with(L!("WezTerm ")) { Wezterm } else { @@ -180,13 +180,15 @@ fn get_protocols(self) -> TtyProtocolsSet { let mut off_chain = vec![]; // Enable focus reporting under tmux - if self == TtyQuirks::Tmux { + if matches!(self, TtyQuirks::Tmux(_)) { on_chain.push(DecsetFocusReporting); off_chain.push(DecrstFocusReporting); } on_chain.push(DecsetBracketedPaste); off_chain.push(DecrstBracketedPaste); - if self != TtyQuirks::Tmux { + if !matches!( + self, TtyQuirks::Tmux(version) if version < (3, 7) + ) { on_chain.push(DecsetColorThemeReporting); off_chain.push(DecrstColorThemeReporting); } @@ -585,15 +587,24 @@ fn drop(&mut self) { fn get_iterm2_version(xtversion: &wstr) -> Option<(u32, u32, u32)> { // TODO split_once let mut xtversion = xtversion.split(' '); - let name = xtversion.next().unwrap(); - let version = xtversion.next()?; - if name != "iTerm2" { + if xtversion.next().unwrap() != "iTerm2" { return None; } - let mut parts = version.split('.'); + let mut version = xtversion.next()?.split('.'); Some(( - wcstoi(parts.next()?).ok()?, - wcstoi(parts.next()?).ok()?, - wcstoi(parts.next()?).ok()?, + wcstoi(version.next()?).ok()?, + wcstoi(version.next()?).ok()?, + wcstoi(version.next()?).ok()?, )) } + +// If we are running under iTerm2, get the version as a tuple of (major, minor, patch). +fn get_tmux_version(xtversion: &wstr) -> Option<(u32, u32)> { + // TODO split_once + let mut xtversion = xtversion.split(' '); + if xtversion.next().unwrap() != "tmux" { + return None; + } + let mut version = xtversion.next()?.split('.'); + Some((wcstoi(version.next()?).ok()?, wcstoi(version.next()?).ok()?)) +} diff --git a/tests/checks/tmux-reporting.fish b/tests/checks/tmux-reporting.fish new file mode 100644 index 000000000..17d682c18 --- /dev/null +++ b/tests/checks/tmux-reporting.fish @@ -0,0 +1,10 @@ +#RUN: %fish %s +#REQUIRES: command -v tmux + +isolated-tmux-start \; \ + set-option -gw window-active-style 'bg=#f0f0f0' \; \ + send-keys ' cat -v' Enter +tmux-sleep +isolated-tmux capture-pane -p +# CHECK: cat -v +# CHECK: prompt 0> cat -v