add ECH handling
This commit is contained in:
1 parent
09f481e753
commit
438822d63b
3 files changed
+27
No files matched your search
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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?", " "]);
|
||||
}
|
||||
Reference in new issue
Block a user