fix(compatibility): clear characters should preserve current styling (#143)

* fix(compatibility): clear characters should preserve current styling

* style(fmt): rustfmt
This commit is contained in:
Aram Drevekenin 2021-01-14 12:48:36 +01:00 committed by GitHub
parent e7f16ed468
commit e6a7ed31f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View file

@ -521,19 +521,27 @@ impl Grid {
let row = self.viewport.get_mut(self.cursor.y).unwrap(); let row = self.viewport.get_mut(self.cursor.y).unwrap();
row.replace_beginning_with(line_part); row.replace_beginning_with(line_part);
} }
pub fn clear_all_after_cursor(&mut self) { pub fn clear_all_after_cursor(&mut self, replace_with: TerminalCharacter) {
self.viewport let cursor_row = self.viewport.get_mut(self.cursor.y).unwrap();
.get_mut(self.cursor.y) cursor_row.truncate(self.cursor.x);
.unwrap() let mut replace_with_columns_in_cursor_row = vec![replace_with; self.width - self.cursor.x];
.truncate(self.cursor.x); cursor_row.append(&mut replace_with_columns_in_cursor_row);
self.viewport.truncate(self.cursor.y + 1);
let replace_with_columns = vec![replace_with; self.width];
self.replace_characters_in_line_after_cursor(replace_with);
for row in self.viewport.iter_mut().skip(self.cursor.y + 1) {
row.replace_columns(replace_with_columns.clone());
}
} }
pub fn clear_cursor_line(&mut self) { pub fn clear_cursor_line(&mut self) {
self.viewport.get_mut(self.cursor.y).unwrap().truncate(0); self.viewport.get_mut(self.cursor.y).unwrap().truncate(0);
} }
pub fn clear_all(&mut self) { pub fn clear_all(&mut self, replace_with: TerminalCharacter) {
self.viewport.clear(); let replace_with_columns = vec![replace_with; self.width];
self.viewport.push(Row::new().canonical()); self.replace_characters_in_line_after_cursor(replace_with);
for row in self.viewport.iter_mut() {
row.replace_columns(replace_with_columns.clone());
}
} }
fn pad_current_line_until(&mut self, position: usize) { fn pad_current_line_until(&mut self, position: usize) {
let current_row = self.viewport.get_mut(self.cursor.y).unwrap(); let current_row = self.viewport.get_mut(self.cursor.y).unwrap();
@ -746,6 +754,9 @@ impl Row {
self.columns.push(terminal_character); self.columns.push(terminal_character);
self.columns.swap_remove(x); self.columns.swap_remove(x);
} }
pub fn replace_columns(&mut self, columns: Vec<TerminalCharacter>) {
self.columns = columns;
}
pub fn push(&mut self, terminal_character: TerminalCharacter) { pub fn push(&mut self, terminal_character: TerminalCharacter) {
self.columns.push(terminal_character); self.columns.push(terminal_character);
} }

View file

@ -443,10 +443,12 @@ impl vte::Perform for TerminalPane {
} }
} else if c == 'J' { } else if c == 'J' {
// clear all (0 => below, 1 => above, 2 => all, 3 => saved) // clear all (0 => below, 1 => above, 2 => all, 3 => saved)
let mut char_to_replace = EMPTY_TERMINAL_CHARACTER;
char_to_replace.styles = self.pending_styles;
if params[0] == 0 { if params[0] == 0 {
self.grid.clear_all_after_cursor(); self.grid.clear_all_after_cursor(char_to_replace);
} else if params[0] == 2 { } else if params[0] == 2 {
self.grid.clear_all(); self.grid.clear_all(char_to_replace);
} }
// TODO: implement 1 // TODO: implement 1
} else if c == 'H' { } else if c == 'H' {
@ -492,7 +494,6 @@ impl vte::Perform for TerminalPane {
Some(&1049) => { Some(&1049) => {
if let Some(alternative_grid) = self.alternative_grid.as_mut() { if let Some(alternative_grid) = self.alternative_grid.as_mut() {
std::mem::swap(&mut self.grid, alternative_grid); std::mem::swap(&mut self.grid, alternative_grid);
// self.grid = alternative_grid;
} }
self.alternative_grid = None; self.alternative_grid = None;
} }