diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index ca105da2c..c8b5c27f2 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1515,6 +1515,18 @@ impl TerminalState { Edit::ScrollDown(n) => self.scroll_down(n as usize), Edit::ScrollUp(n) => self.scroll_up(n as usize), Edit::EraseInDisplay(erase) => self.erase_in_display(erase), + Edit::Repeat(n) => { + let y = self.cursor.y; + let x = self.cursor.x; + let to_copy = x.saturating_sub(1); + let screen = self.screen_mut(); + let line_idx = screen.phys_row(y); + let line = screen.line_mut(line_idx); + if let Some(cell) = line.cells().get(to_copy).cloned() { + line.fill_range(x..=x + n as usize, &cell); + self.set_cursor_pos(&Position::Relative(i64::from(n)), &Position::Relative(0)) + } + } } } diff --git a/term/src/test/csi.rs b/term/src/test/csi.rs index d3e4f21f0..dec4d8e64 100644 --- a/term/src/test/csi.rs +++ b/term/src/test/csi.rs @@ -19,6 +19,15 @@ fn test_vpa() { term.assert_cursor_pos(0, 1, None); } +#[test] +fn test_rep() { + let mut term = TestTerm::new(3, 4, 0); + term.print("h"); + term.cup(1, 0); + term.print("\x1b[2ba"); + assert_visible_contents(&term, &["hhha", " ", " "]); +} + #[test] fn test_ich() { let mut term = TestTerm::new(3, 4, 0); diff --git a/termwiz/src/escape/csi.rs b/termwiz/src/escape/csi.rs index eff391548..38950b72d 100644 --- a/termwiz/src/escape/csi.rs +++ b/termwiz/src/escape/csi.rs @@ -668,6 +668,9 @@ pub enum Edit { /// ED - ERASE IN PAGE (XTerm calls this Erase in Display) EraseInDisplay(EraseInDisplay), + + /// REP - Repeat the preceding character n times + Repeat(u32), } trait EncodeCSIParam { @@ -707,6 +710,7 @@ impl Display for Edit { Edit::ScrollDown(n) => n.write_csi(f, "T")?, Edit::ScrollUp(n) => n.write_csi(f, "S")?, Edit::EraseInDisplay(n) => n.write_csi(f, "J")?, + Edit::Repeat(n) => n.write_csi(f, "b")?, } Ok(()) } @@ -1144,6 +1148,7 @@ impl<'a> CSIParser<'a> { ('Z', &[]) => parse!(Cursor, BackwardTabulation, params), ('a', &[]) => parse!(Cursor, CharacterPositionForward, params), + ('b', &[]) => parse!(Edit, Repeat, params), ('d', &[]) => parse!(Cursor, LinePositionAbsolute, params), ('e', &[]) => parse!(Cursor, LinePositionForward, params), ('f', &[]) => parse!(Cursor, CharacterAndLinePosition, line, col, params),