aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-07 00:43:16 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-07 00:43:16 -0500
commit99ea46bd45204e1c160981642d0be1091e1208d7 (patch)
tree42df60637f7ea4554826e974545dffa09d954092
parent67df88853835ca1646a953f1bcec1ccf3893f3c6 (diff)
downloadvt100-rust-99ea46bd45204e1c160981642d0be1091e1208d7.tar.gz
vt100-rust-99ea46bd45204e1c160981642d0be1091e1208d7.zip
also provide methods to restore the current drawing attribute state
-rw-r--r--src/screen.rs38
1 files changed, 38 insertions, 0 deletions
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<u8> {
+ let mut contents = vec![];
+ self.write_attributes_formatted(&mut contents);
+ contents
+ }
+
+ fn write_attributes_formatted(&self, contents: &mut Vec<u8>) {
+ 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<u8> {
+ let mut contents = vec![];
+ self.write_attributes_diff(&mut contents, prev);
+ contents
+ }
+
+ fn write_attributes_diff(&self, contents: &mut Vec<u8>, 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]