termwiz/term: implement window/pixel size responses

refs: https://github.com/wez/wezterm/issues/211
This commit is contained in:
Wez Furlong committed 2020-06-08 18:44:05 -07:00
1 parent fd512da983
commit ff9151bb9b
2 files changed
+54 -1

No files matched your search

+21
View File
@@ -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),
}
}
+33 -1
View File
@@ -262,6 +262,10 @@ pub enum Window {
ReportWindowSizePixels,
ReportScreenSizePixels,
ReportCellSizePixels,
ReportCellSizePixelsResponse {
width: Option<i64>,
height: Option<i64>,
},
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!(