Skip to content

Commit

Permalink
term: fix DCH removing cells instead of setting to current bg color
Browse files Browse the repository at this point in the history
refs: #789
  • Loading branch information
wez committed Sep 3, 2021
1 parent e9f1c31 commit 67e8bdc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion term/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion term/src/terminalstate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
34 changes: 31 additions & 3 deletions term/src/test/csi.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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]
Expand Down
15 changes: 12 additions & 3 deletions termwiz/src/surface/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 67e8bdc

Please sign in to comment.