mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-25 21:50:20 +00:00
refactor: hoist painter creation up to avoid having to clean if fail
This commit is contained in:
parent
04e4c32aec
commit
a6b48921ee
1 changed files with 6 additions and 8 deletions
14
src/main.rs
14
src/main.rs
|
@ -108,6 +108,12 @@ fn main() -> error::Result<()> {
|
|||
// Create "app" struct, which will control most of the program and store settings/state
|
||||
let mut app = build_app(&matches, &config, &widget_layout, default_widget_id)?;
|
||||
|
||||
// Create painter and set colours.
|
||||
let mut painter = canvas::Painter::init(widget_layout, app.app_config_fields.table_gap);
|
||||
generate_config_colours(&config, &mut painter)?;
|
||||
painter.colours.generate_remaining_cpu_colours();
|
||||
painter.complete_painter_init();
|
||||
|
||||
// Set up up tui and crossterm
|
||||
let mut stdout_val = stdout();
|
||||
execute!(stdout_val, EnterAlternateScreen, EnableMouseCapture)?;
|
||||
|
@ -145,14 +151,6 @@ fn main() -> error::Result<()> {
|
|||
app.used_widgets.clone(),
|
||||
);
|
||||
|
||||
let mut painter = canvas::Painter::init(widget_layout, app.app_config_fields.table_gap);
|
||||
if let Err(config_check) = generate_config_colours(&config, &mut painter) {
|
||||
cleanup_terminal(&mut terminal)?;
|
||||
return Err(config_check);
|
||||
}
|
||||
painter.colours.generate_remaining_cpu_colours();
|
||||
painter.complete_painter_init();
|
||||
|
||||
let mut first_run = true;
|
||||
loop {
|
||||
if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) {
|
||||
|
|
Loading…
Reference in a new issue