From 00f8c4477ee4aa946c6dbebd349461e6b95aaa56 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Wed, 31 Jan 2024 23:23:24 +0100 Subject: [PATCH] Make error widget red --- src/tui/ui.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 05e0ec9..35279db 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -306,28 +306,33 @@ impl<'a, 'b> TrackState<'a, 'b> { pub struct Ui; impl Ui { - fn style(_active: bool) -> Style { - Style::default().fg(Color::White).bg(Color::Black) + fn style(_active: bool, error: bool) -> Style { + let style = Style::default().bg(Color::Black); + if error { + style.fg(Color::Red) + } else { + style.fg(Color::White) + } } - fn block_style(active: bool) -> Style { - Self::style(active) + fn block_style(active: bool, error: bool) -> Style { + Self::style(active, error) } fn highlight_style(active: bool) -> Style { if active { Style::default().fg(Color::White).bg(Color::DarkGray) } else { - Self::style(false) + Self::style(false, false) } } - fn block<'a>(title: &str, active: bool) -> Block<'a> { + fn block<'a>(title: &str, active: bool, error: bool) -> Block<'a> { Block::default() .title_alignment(Alignment::Center) .borders(Borders::ALL) .border_type(BorderType::Rounded) - .style(Self::block_style(active)) + .style(Self::block_style(active, error)) .title(format!(" {title} ")) } @@ -342,8 +347,8 @@ impl Ui { frame.render_stateful_widget( list.highlight_style(Self::highlight_style(active)) .highlight_symbol(">> ") - .style(Self::style(active)) - .block(Self::block(title, active)), + .style(Self::style(active, false)) + .block(Self::block(title, active, false)), area, list_state, ); @@ -358,8 +363,8 @@ impl Ui { ) { frame.render_widget( paragraph - .style(Self::style(active)) - .block(Self::block(title, active)), + .style(Self::style(active, false)) + .block(Self::block(title, active, false)), area, ); } @@ -368,13 +373,14 @@ impl Ui { title: &str, paragraph: Paragraph, area: Rect, + error: bool, frame: &mut Frame<'_, B>, ) { frame.render_widget(Clear, area); frame.render_widget( paragraph - .style(Self::style(true)) - .block(Self::block(title, true)), + .style(Self::style(true, error)) + .block(Self::block(title, true, error)), area, ); } @@ -451,7 +457,7 @@ impl Ui { let artist_selection = &mut selection.artist; let artist_overlay = ArtistOverlay::new(artists, &artist_selection.state); - Self::render_overlay_widget("Artist", artist_overlay.properties, area, frame); + Self::render_overlay_widget("Artist", artist_overlay.properties, area, false, frame); } fn render_reload_overlay(frame: &mut Frame<'_, B>) { @@ -466,7 +472,7 @@ impl Ui { ) .alignment(Alignment::Center); - Self::render_overlay_widget("Reload", reload_text, area, frame); + Self::render_overlay_widget("Reload", reload_text, area, false, frame); } fn render_error_overlay, B: Backend>(msg: S, frame: &mut Frame<'_, B>) { @@ -478,8 +484,7 @@ impl Ui { .alignment(Alignment::Center) .wrap(Wrap { trim: true }); - // FIXME: highlight with red - Self::render_overlay_widget("Error", error_text, area, frame); + Self::render_overlay_widget("Error", error_text, area, true, frame); } }