diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-06 13:30:50 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-06 13:30:50 -0500 |
commit | e21d3005c5ec2304f9f016cd506da93c78da5e51 (patch) | |
tree | a525767295c39544cc25926f15dde951abd59e8b /src | |
parent | d778408be8b12fcc16a8fcaccde49bef927f22e0 (diff) | |
download | vt100-rust-e21d3005c5ec2304f9f016cd506da93c78da5e51.tar.gz vt100-rust-e21d3005c5ec2304f9f016cd506da93c78da5e51.zip |
also add a rows_diff method
Diffstat (limited to 'src')
-rw-r--r-- | src/grid.rs | 2 | ||||
-rw-r--r-- | src/row.rs | 11 | ||||
-rw-r--r-- | src/screen.rs | 27 |
3 files changed, 37 insertions, 3 deletions
diff --git a/src/grid.rs b/src/grid.rs index 075e604..fa6b4b9 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -177,7 +177,7 @@ impl Grid { for (idx, (row, prev_row)) in self.rows().zip(prev.rows()).enumerate() { let (mut new_contents, new_attrs, new_col) = - row.contents_diff(prev_row, prev_attrs); + row.contents_diff(prev_row, 0, self.size.cols, prev_attrs); if !new_contents.is_empty() { contents.extend(format!("\x1b[{};1H", idx + 1).as_bytes()); final_row = idx.try_into().unwrap(); @@ -126,14 +126,21 @@ impl Row { pub fn contents_diff( &self, prev: &Self, + start: u16, + width: u16, attrs: crate::attrs::Attrs, ) -> (Vec<u8>, crate::attrs::Attrs, u16) { let mut skip = 0; let mut contents = vec![]; let mut prev_attrs = attrs; let mut final_col = 0; - for (idx, (cell, prev_cell)) in - self.cells().zip(prev.cells()).enumerate() + + for (idx, (cell, prev_cell)) in self + .cells() + .zip(prev.cells()) + .skip(start as usize) + .take(width as usize) + .enumerate() { if cell == prev_cell { skip += 1; diff --git a/src/screen.rs b/src/screen.rs index 6aa80ba..873eeb3 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -211,6 +211,33 @@ impl Screen { grid_contents } + /// Returns a sequence of terminal byte streams sufficient to turn the + /// subset of each row from `prev` (as described by `start` and `width`) + /// into the corresponding row subset in `self`. + /// + /// You must handle the initial row positioning yourself - each row diff + /// expects to start out positioned at the start of that row. Internal + /// terminal modes (such as application keypad mode or alternate screen + /// mode) will not be included here. + pub fn rows_diff<'a>( + &'a self, + prev: &'a Self, + start: u16, + width: u16, + ) -> impl Iterator<Item = Vec<u8>> + 'a { + self.grid().rows().zip(prev.grid().rows()).map( + move |(row, prev_row)| { + let (contents, ..) = row.contents_diff( + prev_row, + start, + width, + crate::attrs::Attrs::default(), + ); + contents + }, + ) + } + /// Returns the `Cell` object at the given location in the terminal, if it /// exists. pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> { |