diff --git a/term/src/csi.rs b/term/src/csi.rs index 9d1c05342..fa797fba9 100644 --- a/term/src/csi.rs +++ b/term/src/csi.rs @@ -55,6 +55,7 @@ pub enum CSIAction { RestoreCursor, ScrollLines(i64), SoftReset, + EraseCharacter(i64), } /// Constrol Sequence Initiator (CSI) Parser. @@ -479,6 +480,10 @@ impl<'a> Iterator for CSIParser<'a> { ('S', &[], Some(&[])) => Some(CSIAction::ScrollLines(-1)), ('S', &[], Some(&[n])) => Some(CSIAction::ScrollLines(-n)), + // ECH: Erase Character + ('X', &[], Some(&[])) => Some(CSIAction::EraseCharacter(1)), + ('X', &[], Some(&[n])) => Some(CSIAction::EraseCharacter(n)), + // HPR - Character position Relative ('a', &[], Some(&[])) => Some(CSIAction::SetCursorXY { x: Position::Relative(1), diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 64cd9445a..5c827a6a2 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -851,6 +851,16 @@ impl TerminalState { fn perform_csi(&mut self, act: CSIAction) { debug!("{:?}", act); match act { + CSIAction::EraseCharacter(n) => { + let y = self.cursor.y; + let x = self.cursor.x; + let screen = self.screen_mut(); + let blank = CellAttributes::default(); + let limit = (x + n as usize).min(screen.physical_cols); + for x in x..limit as usize { + screen.set_cell(x, y, ' ', &blank); + } + } CSIAction::SoftReset => { self.pen = CellAttributes::default(); // TODO: see https://vt100.net/docs/vt510-rm/DECSTR.html diff --git a/term/src/test/csi.rs b/term/src/test/csi.rs index 8ecc79df7..94cf49c82 100644 --- a/term/src/test/csi.rs +++ b/term/src/test/csi.rs @@ -16,3 +16,15 @@ fn test_vpa() { term.print("\x1b[2d"); term.assert_cursor_pos(0, 1, None); } + +#[test] +fn test_ech() { + let mut term = TestTerm::new(3, 4, 0); + term.print("hey!wat?"); + term.cup(1, 0); + term.print("\x1b[2X"); + assert_visible_contents(&term, &["h !", "wat?", " "]); + // check how we handle overflowing the width + term.print("\x1b[12X"); + assert_visible_contents(&term, &["h ", "wat?", " "]); +}