1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 15:04:32 +03:00

Implement CSI REP

This commit is contained in:
Wez Furlong 2019-03-17 11:20:20 -07:00
parent 2c32eb9337
commit fd2e5855a5
3 changed files with 26 additions and 0 deletions

View File

@ -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))
}
}
}
}

View File

@ -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);

View File

@ -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),