From ff9151bb9b648c11d120023a73e42837490fad0b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 8 Jun 2020 18:44:05 -0700 Subject: [PATCH] termwiz/term: implement window/pixel size responses refs: https://github.com/wez/wezterm/issues/211 --- term/src/terminalstate.rs | 21 +++++++++++++++++++++ termwiz/src/escape/csi.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 3885fc200..617a1cfd0 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1292,6 +1292,26 @@ impl TerminalState { let response = Window::ResizeWindowCells { width, height }; write!(self.writer, "{}", CSI::Window(response)).ok(); } + + Window::ReportCellSizePixels => { + let screen = self.screen(); + let height = screen.physical_rows; + let width = screen.physical_cols; + let response = Window::ReportCellSizePixelsResponse { + width: Some((self.pixel_width / width) as i64), + height: Some((self.pixel_height / height) as i64), + }; + write!(self.writer, "{}", CSI::Window(response)).ok(); + } + + Window::ReportTextAreaSizePixels => { + let response = Window::ResizeWindowPixels { + width: Some(self.pixel_width as i64), + height: Some(self.pixel_height as i64), + }; + write!(self.writer, "{}", CSI::Window(response)).ok(); + } + Window::ChecksumRectangularArea { request_id, top, @@ -1319,6 +1339,7 @@ impl TerminalState { | Window::PushIconAndWindowTitle | Window::PushIconTitle | Window::PushWindowTitle => {} + _ => error!("unhandled Window CSI {:?}", window), } } diff --git a/termwiz/src/escape/csi.rs b/termwiz/src/escape/csi.rs index 8ba51d3ff..06b66198d 100644 --- a/termwiz/src/escape/csi.rs +++ b/termwiz/src/escape/csi.rs @@ -262,6 +262,10 @@ pub enum Window { ReportWindowSizePixels, ReportScreenSizePixels, ReportCellSizePixels, + ReportCellSizePixelsResponse { + width: Option, + height: Option, + }, ReportTextAreaSizeCells, ReportScreenSizeCells, ReportIconLabel, @@ -325,6 +329,12 @@ impl Display for Window { Window::ReportWindowSizePixels => write!(f, "14;2t"), Window::ReportScreenSizePixels => write!(f, "15t"), Window::ReportCellSizePixels => write!(f, "16t"), + Window::ReportCellSizePixelsResponse { width, height } => write!( + f, + "6;{};{}t", + numstr_or_empty(width), + numstr_or_empty(height) + ), Window::ReportTextAreaSizeCells => write!(f, "18t"), Window::ReportScreenSizeCells => write!(f, "19t"), Window::ReportIconLabel => write!(f, "20t"), @@ -1574,7 +1584,14 @@ impl<'a> CSIParser<'a> { height: arg2, }), 5 => Ok(Window::RaiseWindow), - 6 => Ok(Window::LowerWindow), + 6 => match params.len() { + 1 => Ok(Window::LowerWindow), + 3 => Ok(Window::ReportCellSizePixelsResponse { + width: arg1, + height: arg2, + }), + _ => Err(()), + }, 7 => Ok(Window::RefreshWindow), 8 => Ok(Window::ResizeWindowCells { width: arg1, @@ -1957,6 +1974,21 @@ mod test { ); } + #[test] + fn window() { + assert_eq!( + parse('t', &[6], "\x1b[6t"), + vec![CSI::Window(Window::LowerWindow)] + ); + assert_eq!( + parse('t', &[6, 7, 15], "\x1b[6;7;15t"), + vec![CSI::Window(Window::ReportCellSizePixelsResponse { + width: Some(7), + height: Some(15) + })] + ); + } + #[test] fn cursor() { assert_eq!(