aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-09 01:46:51 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-09 01:46:51 -0500
commitc9b957bcdfcd1cedbd8a1f3c5e16d1e4382b54c2 (patch)
tree34bcb2429f31c404f63139406c0c460b75b37243
parent0d69a14a273176c8405602f7543694b65966c7e0 (diff)
downloadvt100-rust-c9b957bcdfcd1cedbd8a1f3c5e16d1e4382b54c2.tar.gz
vt100-rust-c9b957bcdfcd1cedbd8a1f3c5e16d1e4382b54c2.zip
fix attributes_formatted, remove attributes_diff
also improve the documentation and add more tests
-rw-r--r--CHANGELOG.md12
-rw-r--r--src/screen.rs21
-rw-r--r--tests/attr.rs12
3 files changed, 31 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4cbc4e8..fda293f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
# Changelog
+## [Unreleased]
+
+### Fixed
+
+* `Screen::attributes_formatted` now correctly resets previously set attributes
+ where necessary
+
+### Removed
+
+* Removed `Screen::attributes_diff`, since I can't actually think of any
+ situation where it does a thing that makes sense.
+
## [0.11.1] - 2021-03-07
### Changed
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<u8> {
let mut contents = vec![];
@@ -493,26 +499,13 @@ impl Screen {
}
fn write_attributes_formatted(&self, contents: &mut Vec<u8>) {
+ 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<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]
diff --git a/tests/attr.rs b/tests/attr.rs
index 64f4bd4..34ac7af 100644
--- a/tests/attr.rs
+++ b/tests/attr.rs
@@ -9,3 +9,15 @@ fn colors() {
fn attrs() {
helpers::fixture("attrs");
}
+
+#[test]
+fn attributes_formatted() {
+ let mut parser = vt100::Parser::default();
+ assert_eq!(parser.screen().attributes_formatted(), b"\x1b[m");
+ parser.process(b"\x1b[32mfoo\x1b[41mbar\x1b[33mbaz");
+ assert_eq!(parser.screen().attributes_formatted(), b"\x1b[m\x1b[33;41m");
+ parser.process(b"\x1b[1m\x1b[39m");
+ assert_eq!(parser.screen().attributes_formatted(), b"\x1b[m\x1b[41;1m");
+ parser.process(b"\x1b[m");
+ assert_eq!(parser.screen().attributes_formatted(), b"\x1b[m");
+}