From a75279cbbcf8e87879b251a7dca8b7da8842a3e8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Nov 2021 16:59:15 -0500 Subject: add hard_refresh method to fully redraw the screen --- CHANGELOG.md | 6 ++++++ src/blocking/output.rs | 12 ++++++++++++ src/output.rs | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1d4011..0c150bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +* `hard_refresh` to fully redraw the screen + ## [0.1.1] - 2021-11-10 ### Changed diff --git a/src/blocking/output.rs b/src/blocking/output.rs index 77e13d2..cf24e3d 100644 --- a/src/blocking/output.rs +++ b/src/blocking/output.rs @@ -114,6 +114,18 @@ impl Output { self.cur_mut().process(&diff); Ok(()) } + + /// Draws the in-memory screen to the terminal on `stdout`. This clears + /// the screen and redraws it from scratch, rather than using a diff + /// mechanism like `refresh`. This can be useful when the current state of + /// the terminal screen is unknown, such as after the terminal has been + /// resized. + pub async fn hard_refresh(&mut self) -> Result<()> { + let contents = self.next().screen().state_formatted(); + write_stdout(&contents)?; + self.cur_mut().process(&contents); + Ok(()) + } } fn write_stdout(buf: &[u8]) -> Result<()> { diff --git a/src/output.rs b/src/output.rs index 4b2fb06..7669f4c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -127,6 +127,18 @@ impl Output { self.cur_mut().process(&diff); Ok(()) } + + /// Draws the in-memory screen to the terminal on `stdout`. This clears + /// the screen and redraws it from scratch, rather than using a diff + /// mechanism like `refresh`. This can be useful when the current state of + /// the terminal screen is unknown, such as after the terminal has been + /// resized. + pub async fn hard_refresh(&mut self) -> Result<()> { + let contents = self.next().screen().state_formatted(); + write_stdout(&mut self.stdout, &contents).await?; + self.cur_mut().process(&contents); + Ok(()) + } } async fn write_stdout( -- cgit v1.2.3-54-g00ecf