aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-05-04 00:00:46 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-05-04 00:00:46 +0200
commitff52420876fb4e9a2d205d5a819db0234fc36b89 (patch)
treec20295ac9d52b57f049724bbe37f00a36174d689
parent54c663c01a63521ec7959eceed96af1f3f98ecb5 (diff)
downloadmail-ff52420876fb4e9a2d205d5a819db0234fc36b89.tar.gz
wip buffer for less flashing
-rw-r--r--src/window.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/window.rs b/src/window.rs
index baabc30..809ac4d 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -18,7 +18,7 @@ pub enum Line {
}
pub fn truncate_dots(s: &str, to: usize) -> String {
- //TODO We don't have time to do this every tick
+ //TODO Don't do this every tick
let graphemes = s.graphemes(true).collect::<Vec<_>>();
if graphemes.len() >= to {
format!("{}...", graphemes.iter().take(to - 3).fold(String::new(), |acc, s| format!("{}{}", acc, s)))
@@ -41,16 +41,17 @@ impl Window {
}
pub fn draw<W: Write>(&mut self, out: &mut W, area: Area) -> Result<(), std::io::Error> {
+ let mut buffer = Vec::new();
let mut y = area.y;
let mut lines = self.lines.iter().skip(self.scroll);
while y < area.h + 1 {
match lines.next() {
Some(line) => {
- write!(out, "{}", cursor::Goto(area.x, y))?;
+ write!(buffer, "{}", cursor::Goto(area.x, y))?;
match line {
- Line::Normal(s) => write!(out, "{}", truncate_dots(s, area.w as usize))?,
+ Line::Normal(s) => write!(buffer, "{}", truncate_dots(s, area.w as usize))?,
Line::Highlight(s) => write!(
- out,
+ buffer,
"{}{}{}",
color::Fg(color::Red),
truncate_dots(s, area.w as usize),
@@ -62,6 +63,7 @@ impl Window {
None => break,
}
}
+ out.write(&buffer)?;
out.flush()?;
self.lines.clear();