1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-26 16:34:23 +03:00

Add support for Erase In Display

This commit is contained in:
Wez Furlong 2018-01-28 14:12:56 -08:00
parent 39a5b5ef0d
commit 5816928a25
2 changed files with 67 additions and 1 deletions

View File

@ -9,6 +9,14 @@ pub enum LineErase {
All,
}
#[derive(Debug)]
pub enum DisplayErase {
Below,
Above,
All,
SavedLines,
}
#[derive(Debug)]
pub enum CSIAction {
SetPen(CellAttributes),
@ -23,6 +31,7 @@ pub enum CSIAction {
SetInvisible(bool),
SetCursorXY(usize, usize),
EraseInLine(LineErase),
EraseInDisplay(DisplayErase),
}
/// Constrol Sequence Initiator (CSI) Parser.
@ -62,6 +71,30 @@ impl<'a> CSIParser<'a> {
}
}
/// Erase in Display (ED)
fn ed(&mut self, params: &'a [i64]) -> Option<CSIAction> {
match params {
&[] => Some(CSIAction::EraseInDisplay(DisplayErase::Below)),
&[i] => {
self.advance_by(1, params);
match i {
0 => Some(CSIAction::EraseInDisplay(DisplayErase::Below)),
1 => Some(CSIAction::EraseInDisplay(DisplayErase::Above)),
2 => Some(CSIAction::EraseInDisplay(DisplayErase::All)),
3 => Some(CSIAction::EraseInDisplay(DisplayErase::SavedLines)),
_ => {
println!("ed: unknown parameter {:?}", params);
None
}
}
}
_ => {
println!("ed: unhandled csi sequence {:?}", params);
None
}
}
}
/// Erase in Line (EL)
fn el(&mut self, params: &'a [i64]) -> Option<CSIAction> {
match params {
@ -270,10 +303,17 @@ impl<'a> Iterator for CSIParser<'a> {
match (self.byte, params) {
(_, None) => None,
('H', Some(params)) => self.cup(params),
('J', Some(params)) => self.ed(params),
('K', Some(params)) => self.el(params),
('m', Some(params)) => self.sgr(params),
(b, Some(p)) => {
println!("unhandled {} {:?}", b, p);
println!(
"unhandled {} {:?} {:?} ignore={}",
b,
p,
self.intermediates,
self.ignore
);
None
}
}

View File

@ -565,6 +565,32 @@ impl vte::Perform for TerminalState {
}
}
}
CSIAction::EraseInDisplay(erase) => {
let cy = self.cursor_y;
let mut screen = self.screen_mut();
let cols = screen.physical_cols;
let rows = screen.physical_rows;
match erase {
DisplayErase::Below => {
for y in cy..rows {
screen.clear_line(y, 0..cols);
}
}
DisplayErase::Above => {
for y in 0..cy {
screen.clear_line(y, 0..cols);
}
}
DisplayErase::All => {
for y in 0..rows {
screen.clear_line(y, 0..cols);
}
}
DisplayErase::SavedLines => {
println!("ed: no support for xterm Erase Saved Lines yet");
}
}
}
}
}
}