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 --- src/output.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/output.rs') 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