avoid panics in a couple of cases

test case: `cat /dev/random`

refs: https://github.com/wez/wezterm/issues/769
This commit is contained in:
Wez Furlong committed 2021-05-08 01:02:44 -07:00
1 parent ff153ba27f
commit f9a6e265e9
2 files changed
+19 -13

No files matched your search

+15 -11
View File
@@ -2361,18 +2361,22 @@ impl TerminalState {
let line_idx = screen.phys_row(y);
let line = screen.line_mut(line_idx);
let candidate = &line.cells()[to_copy];
if candidate.str() == " " && to_copy > 0 {
// It's a blank. It may be the second part of
// a double-wide pair; look ahead of it.
let prior = &line.cells()[to_copy - 1];
if prior.width() > 1 {
prior.clone()
} else {
candidate.clone()
match line.cells().get(to_copy).cloned() {
None => Cell::new(' ', CellAttributes::default()),
Some(candidate) => {
if candidate.str() == " " && to_copy > 0 {
// It's a blank. It may be the second part of
// a double-wide pair; look ahead of it.
let prior = &line.cells()[to_copy - 1];
if prior.width() > 1 {
prior.clone()
} else {
candidate
}
} else {
candidate
}
}
} else {
candidate.clone()
}
};
+4 -2
View File
@@ -399,8 +399,10 @@ impl Line {
pub fn erase_cell_with_margin(&mut self, x: usize, right_margin: usize) {
self.invalidate_implicit_hyperlinks();
self.invalidate_grapheme_at_or_before(x);
self.cells.remove(x);
if x < self.cells.len() {
self.invalidate_grapheme_at_or_before(x);
self.cells.remove(x);
}
if right_margin <= self.cells.len() {
self.cells.insert(right_margin - 1, Cell::default());
}