diff options
author | Joe Wilm <joe@jwilm.com> | 2016-09-15 08:49:55 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-09-15 08:49:55 -0700 |
commit | c5bc39fe263466986aff622d26d5c93f2f5da0ff (patch) | |
tree | 801971ddbac0b3660184a4e763fa7d78542d4de3 | |
parent | 6c9989819b1f1a78699bc0f81314a9b147ec3cf0 (diff) | |
download | alacritty-c5bc39fe263466986aff622d26d5c93f2f5da0ff.tar.gz alacritty-c5bc39fe263466986aff622d26d5c93f2f5da0ff.zip |
Implement delete_chars
Among other issues, this fixes a very vissible issue with typing in the
middle of a shell command.
-rw-r--r-- | src/term.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/term.rs b/src/term.rs index 62a98400..45e3cf75 100644 --- a/src/term.rs +++ b/src/term.rs @@ -15,6 +15,7 @@ //! Exports the `Term` type which is a high-level API for the Grid use std::mem; use std::ops::{Deref, Range}; +use std::ptr; use ansi::{self, Attr, Handler}; use grid::{Grid, ClearRegion}; @@ -651,7 +652,29 @@ impl ansi::Handler for Term { #[inline] fn delete_chars(&mut self, count: Column) { - err_println!("[unimplemented] delete_chars: {}", count); + // Ensure deleting within terminal bounds + let count = ::std::cmp::min(count, self.size_info.cols()); + + let start = self.cursor.col; + let end = self.cursor.col + count; + let n = (self.size_info.cols() - end).0; + + let line = self.cursor.line; // borrowck + let line = &mut self.grid[line]; + + unsafe { + let src = line[end..].as_ptr(); + let dst = line[start..].as_mut_ptr(); + + ptr::copy(src, dst, n); + } + + // Clear last `count` cells in line. If deleting 1 char, need to delete 1 cell. + let template = self.template_cell.clone(); + let end = self.size_info.cols() - count; + for c in &mut line[end..] { + c.reset(&template); + } } #[inline] |