aboutsummaryrefslogtreecommitdiff
path: root/src/grid.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-07-01 21:13:09 -0700
committerJoe Wilm <joe@jwilm.com>2016-07-01 21:13:09 -0700
commita2ca10643f744244c635fb9b41a3c742e35213ea (patch)
tree7c36ead54423c6e7438803d945a3dc79ba72f249 /src/grid.rs
parent9e45eea0c9af692dee1909b80d0c0552c385cf8c (diff)
downloadalacritty-a2ca10643f744244c635fb9b41a3c742e35213ea.tar.gz
alacritty-a2ca10643f744244c635fb9b41a3c742e35213ea.zip
Implement Term::erase_chars
Fixes last known issue with htop. I think this implementation might not be correct, but I don't yet understand the difference between erasing and deleting (I imagine it's the difference between graphics state vs grid state). Will probably need to circle back here. Adds all range indexing operations to rows. Some were needed for the erase_chars impl, and the rest are there for fully generality.
Diffstat (limited to 'src/grid.rs')
-rw-r--r--src/grid.rs46
1 files changed, 20 insertions, 26 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);