aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-11 16:59:15 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-11 16:59:15 -0500
commita75279cbbcf8e87879b251a7dca8b7da8842a3e8 (patch)
treef732c4ff05fcd8ffeb664519ddb901a45689d4b5
parenta6cdd5f5fdf3bb0b7200cd2f5a4c27df92c1330f (diff)
downloadtextmode-a75279cbbcf8e87879b251a7dca8b7da8842a3e8.tar.gz
textmode-a75279cbbcf8e87879b251a7dca8b7da8842a3e8.zip
add hard_refresh method to fully redraw the screen
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/blocking/output.rs12
-rw-r--r--src/output.rs12
3 files changed, 30 insertions, 0 deletions
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(