2
0
Fork 0
mirror of https://github.com/ClementTsang/bottom synced 2025-02-15 12:48:28 +00:00

Refactoring - moved canvas into its own struct... time to do some more fun optimization.

This commit is contained in:
ClementTsang 2020-02-04 22:44:49 -05:00
parent 41d56d8a9b
commit e0115624a9
2 changed files with 908 additions and 891 deletions

File diff suppressed because it is too large Load diff

View file

@ -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<()> {