1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 03:39:16 +03:00

Add basic support for ICH which is used by bash CTRL-R

This commit is contained in:
Wez Furlong 2018-03-09 22:15:06 -08:00
parent 1c4500082f
commit 197819db6d
4 changed files with 42 additions and 0 deletions

View File

@ -59,6 +59,7 @@ pub enum CSIAction {
SoftReset,
EraseCharacter(i64),
DeleteCharacter(i64),
InsertCharacter(i64),
}
/// Constrol Sequence Initiator (CSI) Parser.
@ -430,6 +431,11 @@ impl<'a> Iterator for CSIParser<'a> {
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
match (self.byte, self.intermediates, params) {
(_, _, None) => None,
// ICH: Insert Character
('@', &[], Some(&[])) => Some(CSIAction::InsertCharacter(1)),
('@', &[], Some(&[n])) => Some(CSIAction::InsertCharacter(n)),
// CUU - Cursor Up n times
('A', &[], Some(&[])) => Some(CSIAction::SetCursorXY {
x: Position::Relative(0),

View File

@ -100,9 +100,17 @@ impl Screen {
self.lines.iter().map(|l| l.clone()).collect()
}
pub fn insert_cell(&mut self, x: usize, y: VisibleRowIndex) {
let line_idx = self.phys_row(y);
let line = self.line_mut(line_idx);
line.invalidate_implicit_links();
line.cells.insert(x, Cell::default());
}
pub fn erase_cell(&mut self, x: usize, y: VisibleRowIndex) {
let line_idx = self.phys_row(y);
let line = self.line_mut(line_idx);
line.invalidate_implicit_links();
line.cells.remove(x);
line.cells.push(Cell::default());
}

View File

@ -1034,6 +1034,20 @@ impl TerminalState {
}
self.clear_selection_if_intersects(x..limit, y as ScrollbackOrVisibleRowIndex);
}
CSIAction::InsertCharacter(n) => {
let y = self.cursor.y;
let x = self.cursor.x;
// TODO: this limiting behavior may not be correct. There's also a
// SEM sequence that impacts the scope of ICH and ECH to consider.
let limit = (x + n as usize).min(self.screen().physical_cols);
{
let screen = self.screen_mut();
for x in x..limit as usize {
screen.insert_cell(x, y);
}
}
self.clear_selection_if_intersects(x..limit, y as ScrollbackOrVisibleRowIndex);
}
CSIAction::EraseCharacter(n) => {
let y = self.cursor.y;
let x = self.cursor.x;

View File

@ -19,6 +19,20 @@ fn test_vpa() {
term.assert_cursor_pos(0, 1, None);
}
#[test]
fn test_ich() {
let mut term = TestTerm::new(3, 4, 0);
term.print("hey!wat?");
term.cup(1, 0);
term.print("\x1b[2@");
assert_visible_contents(&term, &["h ey!", "wat?", " "]);
// check how we handle overflowing the width
term.print("\x1b[12@");
assert_visible_contents(&term, &["h ey!", "wat?", " "]);
term.print("\x1b[-12@");
assert_visible_contents(&term, &["h ey!", "wat?", " "]);
}
#[test]
fn test_ech() {
let mut term = TestTerm::new(3, 4, 0);