diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-10 06:17:09 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-10 08:08:14 -0500 |
commit | 168a91a9ddc331cd3b8e5c32f7701f2b0973b147 (patch) | |
tree | 6b2df47bf18a731a9814bb875ce231e28cad1bf0 /src/grid.rs | |
parent | b04c0e6e97765aeb888479c5e0bc27d54de60659 (diff) | |
download | vt100-rust-168a91a9ddc331cd3b8e5c32f7701f2b0973b147.tar.gz vt100-rust-168a91a9ddc331cd3b8e5c32f7701f2b0973b147.zip |
optimize attribute setting a bit
Diffstat (limited to 'src/grid.rs')
-rw-r--r-- | src/grid.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/grid.rs b/src/grid.rs index 1cc4daf..a546c43 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -179,11 +179,14 @@ impl Grid { } } - pub fn write_contents_formatted(&self, contents: &mut Vec<u8>) { + pub fn write_contents_formatted( + &self, + contents: &mut Vec<u8>, + ) -> crate::attrs::Attrs { write!( contents, "{}{}", - crate::term::Attrs::new(), + crate::term::ClearAttrs::new(), crate::term::ClearScreen::new() ) .unwrap(); @@ -211,13 +214,17 @@ impl Grid { write!(contents, "{}", crate::term::MoveTo::new(self.pos)) .unwrap(); } - } - pub fn write_contents_diff(&self, contents: &mut Vec<u8>, prev: &Self) { - write!(contents, "{}", crate::term::Attrs::default()).unwrap(); + prev_attrs + } + pub fn write_contents_diff( + &self, + contents: &mut Vec<u8>, + prev: &Self, + mut prev_attrs: crate::attrs::Attrs, + ) -> crate::attrs::Attrs { let mut prev_pos = prev.pos; - let mut prev_attrs = crate::attrs::Attrs::default(); let mut wrapping = false; for (i, (row, prev_row)) in self.visible_rows().zip(prev.visible_rows()).enumerate() @@ -242,6 +249,8 @@ impl Grid { write!(contents, "{}", crate::term::MoveTo::new(self.pos)) .unwrap(); } + + prev_attrs } pub fn erase_all(&mut self, bgcolor: crate::attrs::Color) { |