From f8555701c71847a953bc21c602b6a070b757a107 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Mar 2021 01:58:27 -0500 Subject: add Screen::state_formatted and Screen::state_diff --- src/screen.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/screen.rs b/src/screen.rs index 9affeef..300e05d 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -226,6 +226,32 @@ impl Screen { } } + /// Return escape codes sufficient to reproduce the entire contents of the + /// current terminal state. This is a convenience wrapper around + /// `contents_formatted`, `input_mode_formatted`, and `title_formatted`. + #[must_use] + pub fn state_formatted(&self) -> Vec { + let mut contents = vec![]; + self.write_contents_formatted(&mut contents); + self.write_input_mode_formatted(&mut contents); + self.write_title_formatted(&mut contents); + contents + } + + /// Return escape codes sufficient to turn the terminal state of the + /// screen `prev` into the current terminal state. This is a convenience + /// wrapper around `contents_diff`, `input_mode_diff`, `title_diff`, and + /// `bells_diff`. + #[must_use] + pub fn state_diff(&self, prev: &Self) -> Vec { + let mut contents = vec![]; + self.write_contents_diff(&mut contents, prev); + self.write_input_mode_diff(&mut contents, prev); + self.write_title_diff(&mut contents, prev); + self.write_bells_diff(&mut contents, prev); + contents + } + /// Returns the formatted visible contents of the terminal. /// /// Formatting information will be included inline as terminal escape -- cgit v1.2.3-54-g00ecf