Implement blank character insertion

This is used by things like Bash's reverse-i-search and things get
*very* messed up without it.
This commit is contained in:
Joe Wilm 2016-10-10 08:29:51 -07:00
parent b80abe9a54
commit f69ea009a3
2 changed files with 26 additions and 4 deletions

View File

@ -107,7 +107,7 @@ pub trait Handler {
fn goto_col(&mut self, Column) {}
/// Insert blank characters in current line starting from cursor
fn insert_blank(&mut self, usize) {}
fn insert_blank(&mut self, Column) {}
/// Move cursor up `rows`
fn move_up(&mut self, Line) {}
@ -470,7 +470,7 @@ impl<'a, H: Handler + TermInfo + 'a> vte::Perform for Performer<'a, H> {
}
match action {
'@' => handler.insert_blank(arg_or_default!(idx: 0, default: 1) as usize),
'@' => handler.insert_blank(Column(arg_or_default!(idx: 0, default: 1) as usize)),
'A' => {
handler.move_up(Line(arg_or_default!(idx: 0, default: 1) as usize));
},

View File

@ -500,8 +500,30 @@ impl ansi::Handler for Term {
}
#[inline]
fn insert_blank(&mut self, num: usize) {
err_println!("[unimplemented] insert_blank: {}", num);
fn insert_blank(&mut self, count: Column) {
// Ensure inserting within terminal bounds
let count = ::std::cmp::min(count, self.size_info.cols() - self.cursor.col);
let source = self.cursor.col;
let destination = self.cursor.col + count;
let num_cells = (self.size_info.cols() - destination).0;
let line = self.cursor.line; // borrowck
let line = &mut self.grid[line];
unsafe {
let src = line[source..].as_ptr();
let dst = line[destination..].as_mut_ptr();
ptr::copy(src, dst, num_cells);
}
// Cells were just moved out towards the end of the line; fill in
// between source and dest with blanks.
let template = self.template_cell.clone();
for c in &mut line[source..destination] {
c.reset(&template);
}
}
#[inline]