diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-11-11 16:59:15 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-11-11 16:59:15 -0500 |
commit | a75279cbbcf8e87879b251a7dca8b7da8842a3e8 (patch) | |
tree | f732c4ff05fcd8ffeb664519ddb901a45689d4b5 /src | |
parent | a6cdd5f5fdf3bb0b7200cd2f5a4c27df92c1330f (diff) | |
download | textmode-a75279cbbcf8e87879b251a7dca8b7da8842a3e8.tar.gz textmode-a75279cbbcf8e87879b251a7dca8b7da8842a3e8.zip |
add hard_refresh method to fully redraw the screen
Diffstat (limited to 'src')
-rw-r--r-- | src/blocking/output.rs | 12 | ||||
-rw-r--r-- | src/output.rs | 12 |
2 files changed, 24 insertions, 0 deletions
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( |