From c9b957bcdfcd1cedbd8a1f3c5e16d1e4382b54c2 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Mar 2021 01:46:51 -0500 Subject: fix attributes_formatted, remove attributes_diff also improve the documentation and add more tests --- src/screen.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/screen.rs') diff --git a/src/screen.rs b/src/screen.rs index cb6b970..9affeef 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -485,6 +485,12 @@ impl Screen { /// * italic /// * underline /// * inverse + /// + /// This is not typically necessary, since `contents_formatted` will leave + /// the current active drawing attributes in the correct state, but this + /// can be useful in the case of drawing additional things on top of a + /// terminal output, since you will need to restore the terminal state + /// without the terminal contents necessarily being the same. #[must_use] pub fn attributes_formatted(&self) -> Vec { let mut contents = vec![]; @@ -493,26 +499,13 @@ impl Screen { } fn write_attributes_formatted(&self, contents: &mut Vec) { + crate::term::ClearAttrs::default().write_buf(contents); self.attrs.write_escape_code_diff( contents, &crate::attrs::Attrs::default(), ); } - /// Returns terminal escape sequences sufficient to change the previous - /// terminal's drawing attributes to the drawing attributes enabled in the - /// current terminal. - #[must_use] - pub fn attributes_diff(&self, prev: &Self) -> Vec { - let mut contents = vec![]; - self.write_attributes_diff(&mut contents, prev); - contents - } - - fn write_attributes_diff(&self, contents: &mut Vec, prev: &Self) { - self.attrs.write_escape_code_diff(contents, &prev.attrs); - } - /// Returns the `Cell` object at the given location in the terminal, if it /// exists. #[must_use] -- cgit v1.2.3-54-g00ecf