From a6b48921ee7fe49874bc629f107e06a688603547 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Thu, 23 Apr 2020 15:33:31 -0400 Subject: [PATCH] refactor: hoist painter creation up to avoid having to clean if fail --- src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 42df73ff..675e8cdf 100644 --- a/src/main.rs +++ b/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)) {