From 99ea46bd45204e1c160981642d0be1091e1208d7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 7 Mar 2021 00:43:16 -0500 Subject: also provide methods to restore the current drawing attribute state --- src/screen.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/screen.rs b/src/screen.rs index 3d242aa..55de967 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -478,6 +478,44 @@ impl Screen { } } + /// Returns terminal escape sequences sufficient to set the current + /// terminal's drawing attributes. + /// + /// Supported drawing attributes are: + /// * fgcolor + /// * bgcolor + /// * bold + /// * italic + /// * underline + /// * inverse + #[must_use] + pub fn attributes_formatted(&self) -> Vec { + let mut contents = vec![]; + self.write_attributes_formatted(&mut contents); + contents + } + + fn write_attributes_formatted(&self, contents: &mut Vec) { + 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