aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-06 13:30:50 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-06 13:30:50 -0500
commite21d3005c5ec2304f9f016cd506da93c78da5e51 (patch)
treea525767295c39544cc25926f15dde951abd59e8b /src
parentd778408be8b12fcc16a8fcaccde49bef927f22e0 (diff)
downloadvt100-rust-e21d3005c5ec2304f9f016cd506da93c78da5e51.tar.gz
vt100-rust-e21d3005c5ec2304f9f016cd506da93c78da5e51.zip
also add a rows_diff method
Diffstat (limited to 'src')
-rw-r--r--src/grid.rs2
-rw-r--r--src/row.rs11
-rw-r--r--src/screen.rs27
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();
diff --git a/src/row.rs b/src/row.rs
index fb31594..7b2ab99 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -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> {