summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 6db1356d..068a72cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -230,8 +230,9 @@ fn main() -> error::Result<()> {
});
}
+ let mut painter = canvas::Painter::default();
loop {
- // TODO: [OPT] this should not block... let's properly use tick rates and non-blocking, okay?
+ // TODO: [OPT] this should not block...
if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) {
match recv {
Event::KeyInput(event) => {
@@ -372,18 +373,26 @@ fn main() -> error::Result<()> {
}
}
- // Draw!
- if let Err(err) = canvas::draw_data(&mut terminal, &mut app) {
- cleanup_terminal(&mut terminal)?;
- error!("{}", err);
- return Err(err);
- }
+ try_drawing(&mut terminal, &mut app, &mut painter)?;
}
cleanup_terminal(&mut terminal)?;
Ok(())
}
+fn try_drawing(
+ terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
+ app: &mut app::App, painter: &mut canvas::Painter,
+) -> error::Result<()> {
+ if let Err(err) = painter.draw_data(terminal, app) {
+ cleanup_terminal(terminal)?;
+ error!("{}", err);
+ return Err(err);
+ }
+
+ Ok(())
+}
+
fn cleanup_terminal(
terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
) -> error::Result<()> {