diff --git a/docs/changelog.md b/docs/changelog.md index 17a20f068..23bc97528 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -28,6 +28,7 @@ As features stabilize some brief notes about them will accumulate here. * Fixed: ALT + Arrow, PageUp/PageDown, Ins, Del, Home, End incorrectly sent ESC prefixed key sequences. [#892](https://github.com/wez/wezterm/issues/892) * New: Added [SendKey](config/lua/keyassignment/SendKey.md) key assignment action that makes it more convenient to rebind the key input that is sent to a pane. * Fixed: Crash due to Out of Memory condition when the iTerm2 protocol was used to send excessively large PNG files [#1031](https://github.com/wez/wezterm/issues/1031) +* Fixed: `DCH` sequence would remove cells and replace them with default-blank cells instead of blank-cells-with-current-bg-color. [#789](https://github.com/wez/wezterm/issues/789) ### 20210814-124438-54e29167 diff --git a/term/src/screen.rs b/term/src/screen.rs index e18f505b1..4e4927be7 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -319,10 +319,11 @@ impl Screen { y: VisibleRowIndex, right_margin: usize, seqno: SequenceNo, + blank_attr: CellAttributes, ) { let line_idx = self.phys_row(y); let line = self.line_mut(line_idx); - line.erase_cell_with_margin(x, right_margin, seqno); + line.erase_cell_with_margin(x, right_margin, seqno, blank_attr); } /// Set a cell. the x and y coordinates are relative to the visible screeen diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index eced1394b..5cae976c8 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -1708,9 +1708,10 @@ impl TerminalState { let right_margin = self.left_and_right_margins.end; let limit = (x + n as usize).min(right_margin); + let blank_attr = self.pen.clone_sgr_only(); let screen = self.screen_mut(); for _ in x..limit as usize { - screen.erase_cell(x, y, right_margin, seqno); + screen.erase_cell(x, y, right_margin, seqno, blank_attr.clone()); } } } diff --git a/term/src/test/csi.rs b/term/src/test/csi.rs index 22302b453..49a6ced8c 100644 --- a/term/src/test/csi.rs +++ b/term/src/test/csi.rs @@ -1,4 +1,32 @@ use super::*; +use termwiz::color::AnsiColor; + +/// In this issue, the `CSI 2 P` sequence incorrectly removed two +/// cells from the line, leaving them effectively blank, when those +/// two cells should have been erased to the current background +/// color as set by `CSI 40 m` +#[test] +fn test_789() { + let mut term = TestTerm::new(1, 8, 0); + term.print("\x1b[40m\x1b[Kfoo\x1b[2P"); + + let black = CellAttributes::default() + .set_background(AnsiColor::Black) + .clone(); + let mut line = Line::from_text("foo", &black); + line.resize(8, 0); + for x in 3..8 { + line.set_cell(x, Cell::blank_with_attrs(black.clone()), 0); + } + + assert_lines_equal( + file!(), + line!(), + &term.screen().visible_lines(), + &[line], + Compare::TEXT | Compare::ATTRS, + ); +} #[test] fn test_vpa() { @@ -76,14 +104,14 @@ fn test_dch() { term.print("hello world"); term.cup(1, 0); term.print("\x1b[P"); - assert_visible_contents(&term, file!(), line!(), &["hllo world "]); + assert_visible_contents(&term, file!(), line!(), &["hllo world "]); term.cup(4, 0); term.print("\x1b[2P"); - assert_visible_contents(&term, file!(), line!(), &["hlloorld "]); + assert_visible_contents(&term, file!(), line!(), &["hlloorld "]); term.print("\x1b[-2P"); - assert_visible_contents(&term, file!(), line!(), &["hlloorld "]); + assert_visible_contents(&term, file!(), line!(), &["hlloorld "]); } #[test] diff --git a/termwiz/src/surface/line.rs b/termwiz/src/surface/line.rs index 404614a92..a684dcca0 100644 --- a/termwiz/src/surface/line.rs +++ b/termwiz/src/surface/line.rs @@ -539,14 +539,23 @@ impl Line { self.update_last_change_seqno(seqno); } - pub fn erase_cell_with_margin(&mut self, x: usize, right_margin: usize, seqno: SequenceNo) { + pub fn erase_cell_with_margin( + &mut self, + x: usize, + right_margin: usize, + seqno: SequenceNo, + blank_attr: CellAttributes, + ) { self.invalidate_implicit_hyperlinks(seqno); 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()); + if right_margin <= self.cells.len() + 1 + /* we just removed one */ + { + self.cells + .insert(right_margin - 1, Cell::blank_with_attrs(blank_attr)); } self.update_last_change_seqno(seqno); }