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:
parent
e7f16ed468
commit
e6a7ed31f6
2 changed files with 24 additions and 12 deletions
|
|
@ -521,19 +521,27 @@ impl Grid {
|
|||
let row = self.viewport.get_mut(self.cursor.y).unwrap();
|
||||
row.replace_beginning_with(line_part);
|
||||
}
|
||||
pub fn clear_all_after_cursor(&mut self) {
|
||||
self.viewport
|
||||
.get_mut(self.cursor.y)
|
||||
.unwrap()
|
||||
.truncate(self.cursor.x);
|
||||
self.viewport.truncate(self.cursor.y + 1);
|
||||
pub fn clear_all_after_cursor(&mut self, replace_with: TerminalCharacter) {
|
||||
let cursor_row = self.viewport.get_mut(self.cursor.y).unwrap();
|
||||
cursor_row.truncate(self.cursor.x);
|
||||
let mut replace_with_columns_in_cursor_row = vec![replace_with; self.width - self.cursor.x];
|
||||
cursor_row.append(&mut replace_with_columns_in_cursor_row);
|
||||
|
||||
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) {
|
||||
self.viewport.get_mut(self.cursor.y).unwrap().truncate(0);
|
||||
}
|
||||
pub fn clear_all(&mut self) {
|
||||
self.viewport.clear();
|
||||
self.viewport.push(Row::new().canonical());
|
||||
pub fn clear_all(&mut self, replace_with: TerminalCharacter) {
|
||||
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() {
|
||||
row.replace_columns(replace_with_columns.clone());
|
||||
}
|
||||
}
|
||||
fn pad_current_line_until(&mut self, position: usize) {
|
||||
let current_row = self.viewport.get_mut(self.cursor.y).unwrap();
|
||||
|
|
@ -746,6 +754,9 @@ impl Row {
|
|||
self.columns.push(terminal_character);
|
||||
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) {
|
||||
self.columns.push(terminal_character);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -443,10 +443,12 @@ impl vte::Perform for TerminalPane {
|
|||
}
|
||||
} else if c == 'J' {
|
||||
// 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 {
|
||||
self.grid.clear_all_after_cursor();
|
||||
self.grid.clear_all_after_cursor(char_to_replace);
|
||||
} else if params[0] == 2 {
|
||||
self.grid.clear_all();
|
||||
self.grid.clear_all(char_to_replace);
|
||||
}
|
||||
// TODO: implement 1
|
||||
} else if c == 'H' {
|
||||
|
|
@ -492,7 +494,6 @@ impl vte::Perform for TerminalPane {
|
|||
Some(&1049) => {
|
||||
if let Some(alternative_grid) = self.alternative_grid.as_mut() {
|
||||
std::mem::swap(&mut self.grid, alternative_grid);
|
||||
// self.grid = alternative_grid;
|
||||
}
|
||||
self.alternative_grid = None;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue