diff --git a/src/action.rs b/src/action.rs index b582068..635a1ba 100644 --- a/src/action.rs +++ b/src/action.rs @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize}; use strum::Display; -use crate::{app::Mode, system::disk::Disk}; +use crate::{app::Mode, components::popup::Type, system::disk::Disk}; #[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] pub enum Action { @@ -28,7 +28,7 @@ pub enum Action { Quit, ClearScreen, DismissPopup, - DisplayPopup(String), + DisplayPopup(Type, String), Error(String), Help, KeyUp, diff --git a/src/app.rs b/src/app.rs index 5f2e2b6..5e3b20c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -32,7 +32,12 @@ use tracing::{debug, info}; use crate::{ action::Action, components::{ - footer::Footer, fps::FpsCounter, left::Left, popup::Popup, right::Right, title::Title, + footer::Footer, + fps::FpsCounter, + left::Left, + popup::{Popup, Type}, + right::Right, + title::Title, Component, }, config::Config, @@ -253,9 +258,10 @@ impl App { self.action_tx.send(Action::UpdateDiskList(disks.clone()))?; } Mode::Done => { - self.action_tx.send(Action::DisplayPopup(String::from( - "COMPLETE\n\nThank you for using this tool!", - )))?; + self.action_tx.send(Action::DisplayPopup( + Type::Success, + String::from("COMPLETE\n\n\nThank you for using this tool!"), + ))?; } _ => {} } diff --git a/src/components/popup.rs b/src/components/popup.rs index 8ca499a..a1e1f35 100644 --- a/src/components/popup.rs +++ b/src/components/popup.rs @@ -15,15 +15,26 @@ // use color_eyre::Result; use ratatui::{prelude::*, widgets::*}; +use serde::{Deserialize, Serialize}; +use strum::Display; use tokio::sync::mpsc::UnboundedSender; use super::Component; use crate::{action::Action, app::Mode, config::Config}; +#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] +pub enum Type { + #[default] + Info, + Error, + Success, +} + #[derive(Default)] pub struct Popup { command_tx: Option>, config: Config, + popup_type: Type, popup_text: String, } @@ -56,7 +67,10 @@ impl Component for Popup { // add any logic here that should run on every render } Action::DismissPopup => self.popup_text.clear(), - Action::DisplayPopup(new_text) => self.popup_text = String::from(new_text), + Action::DisplayPopup(new_type, new_text) => { + self.popup_type = new_type; + self.popup_text = String::from(new_text); + } Action::SetMode(Mode::ScanDisks) => self.popup_text = String::from("Scanning Disks..."), _ => {} } @@ -69,10 +83,17 @@ impl Component for Popup { return Ok(()); } - let popup_block = Block::default() - .borders(Borders::ALL) - .style(Style::default().cyan().bold()); - let popup = Paragraph::new(vec![Line::from(Span::raw(&self.popup_text))]) + // Set style/color + let mut style = Style::default().bold(); + match self.popup_type { + Type::Info => style = style.cyan(), + Type::Error => style = style.red(), + Type::Success => style = style.green(), + } + + // Build block + let popup_block = Block::default().borders(Borders::ALL).style(style); + let popup = Paragraph::new(String::from(&self.popup_text)) .block(popup_block) .centered() .wrap(Wrap { trim: false });