aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grid.rs46
-rw-r--r--src/term.rs12
2 files changed, 31 insertions, 27 deletions
diff --git a/src/grid.rs b/src/grid.rs
index c3f4785a..3ce15280 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -14,7 +14,7 @@
//
//! Functions for computing properties of the terminal grid
-use std::ops::{Index, IndexMut, Deref, DerefMut, Range, RangeTo, RangeFrom};
+use std::ops::{Index, IndexMut, Deref, DerefMut, Range, RangeTo, RangeFrom, RangeFull};
use std::cmp::Ordering;
use std::slice::{Iter, IterMut};
@@ -262,35 +262,29 @@ impl IndexMut<usize> for Row {
}
}
-impl Index<RangeFrom<usize>> for Row {
- type Output = [Cell];
- #[inline]
- fn index<'a>(&'a self, index: RangeFrom<usize>) -> &'a [Cell] {
- &self.0[index]
- }
-}
-
-impl IndexMut<RangeFrom<usize>> for Row {
- #[inline]
- fn index_mut<'a>(&'a mut self, index: RangeFrom<usize>) -> &'a mut [Cell] {
- &mut self.0[index]
- }
-}
+macro_rules! row_index_range {
+ ($range:ty) => {
+ impl Index<$range> for Row {
+ type Output = [Cell];
+ #[inline]
+ fn index<'a>(&'a self, index: $range) -> &'a [Cell] {
+ &self.0[index]
+ }
+ }
-impl Index<RangeTo<usize>> for Row {
- type Output = [Cell];
- #[inline]
- fn index<'a>(&'a self, index: RangeTo<usize>) -> &'a [Cell] {
- &self.0[index]
+ impl IndexMut<$range> for Row {
+ #[inline]
+ fn index_mut<'a>(&'a mut self, index: $range) -> &'a mut [Cell] {
+ &mut self.0[index]
+ }
+ }
}
}
-impl IndexMut<RangeTo<usize>> for Row {
- #[inline]
- fn index_mut<'a>(&'a mut self, index: RangeTo<usize>) -> &'a mut [Cell] {
- &mut self.0[index]
- }
-}
+row_index_range!(Range<usize>);
+row_index_range!(RangeTo<usize>);
+row_index_range!(RangeFrom<usize>);
+row_index_range!(RangeFull);
pub trait ClearRegion<T> {
fn clear_region(&mut self, region: T);
diff --git a/src/term.rs b/src/term.rs
index aff95b55..3ffe9c47 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -483,7 +483,17 @@ impl ansi::Handler for Term {
self.scroll(count as isize);
}
}
- fn erase_chars(&mut self, count: i64) { println!("erase_chars: {}", count); }
+ fn erase_chars(&mut self, count: i64) {
+ println!("erase_chars: {}", count);
+ let row_index = self.cursor.y as usize;
+ let col_index = self.cursor.x as usize;
+ let count = count as usize;
+
+ let row = &mut self.grid[row_index];
+ for c in &mut row[col_index..(count + col_index)] {
+ c.reset();
+ }
+ }
fn delete_chars(&mut self, count: i64) { println!("delete_chars: {}", count); }
fn move_backward_tabs(&mut self, count: i64) { println!("move_backward_tabs: {}", count); }
fn move_forward_tabs(&mut self, count: i64) { println!("move_forward_tabs: {}", count); }