diff --git a/src/app.rs b/src/app.rs index 55b04247..13df31d7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -56,7 +56,7 @@ impl App { do_quit: false, current_commands: Vec::new(), help: HelpComponent::new(&theme), - msg: MsgComponent::default(), + msg: MsgComponent::new(&theme), tab: 0, revlog: Revlog::new(&sender, &theme), status_tab: Status::new(&sender, &queue, &theme), @@ -263,7 +263,7 @@ impl App { } } } - InternalEvent::ShowMsg(msg) => { + InternalEvent::ShowErrorMsg(msg) => { self.msg.show_msg(msg.as_str()); flags.insert(NeedsUpdate::ALL); } diff --git a/src/components/commit.rs b/src/components/commit.rs index 64e1c507..3c7bd06d 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -127,7 +127,7 @@ impl CommitComponent { { error!("commit-msg hook error: {}", e); self.queue.borrow_mut().push_back( - InternalEvent::ShowMsg(format!( + InternalEvent::ShowErrorMsg(format!( "commit-msg hook error:\n{}", e )), @@ -138,7 +138,7 @@ impl CommitComponent { if let Err(e) = sync::commit(CWD, &self.msg) { error!("commit error: {}", &e); self.queue.borrow_mut().push_back( - InternalEvent::ShowMsg(format!( + InternalEvent::ShowErrorMsg(format!( "commit failed:\n{}", &e )), @@ -151,7 +151,7 @@ impl CommitComponent { { error!("post-commit hook error: {}", e); self.queue.borrow_mut().push_back( - InternalEvent::ShowMsg(format!( + InternalEvent::ShowErrorMsg(format!( "post-commit hook error:\n{}", e )), diff --git a/src/components/msg.rs b/src/components/msg.rs index 6c1baf7f..459262b6 100644 --- a/src/components/msg.rs +++ b/src/components/msg.rs @@ -2,36 +2,45 @@ use super::{ visibility_blocking, CommandBlocking, CommandInfo, Component, DrawableComponent, }; -use crate::{components::dialog_paragraph, keys, strings, ui}; +use crate::{keys, strings, ui}; use crossterm::event::Event; use std::borrow::Cow; use strings::commands; use tui::{ backend::Backend, - layout::Rect, - widgets::{Clear, Text}, + layout::{Alignment, Rect}, + widgets::{Block, Borders, Clear, Paragraph, Text}, Frame, }; +use ui::style::Theme; -#[derive(Default)] pub struct MsgComponent { msg: String, visible: bool, + theme: Theme, } impl DrawableComponent for MsgComponent { fn draw(&mut self, f: &mut Frame, _rect: Rect) { - if self.visible { - let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))]; - - let area = ui::centered_rect_absolute(65, 25, f.size()); - f.render_widget(Clear, area); - f.render_widget( - dialog_paragraph(strings::MSG_TITLE, txt.iter()) - .wrap(true), - area, - ); + if !self.visible { + return; } + let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))]; + + let area = ui::centered_rect_absolute(65, 25, f.size()); + f.render_widget(Clear, area); + f.render_widget( + Paragraph::new(txt.iter()) + .block( + Block::default() + .title(strings::MSG_TITLE_ERROR) + .title_style(self.theme.text_danger()) + .borders(Borders::ALL), + ) + .alignment(Alignment::Left) + .wrap(true), + area, + ); } } @@ -78,6 +87,13 @@ impl Component for MsgComponent { } impl MsgComponent { + pub fn new(theme: &Theme) -> Self { + Self { + msg: String::new(), + visible: false, + theme: *theme, + } + } /// pub fn show_msg(&mut self, msg: &str) { self.msg = msg.to_string(); diff --git a/src/queue.rs b/src/queue.rs index 0deb2186..ec81a5fe 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -30,7 +30,7 @@ pub enum InternalEvent { /// AddHunk(u64), /// - ShowMsg(String), + ShowErrorMsg(String), /// Update(NeedsUpdate), /// diff --git a/src/strings.rs b/src/strings.rs index a5eec190..a94db3d5 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -8,7 +8,7 @@ pub static TAB_DIVIDER: &str = " | "; pub static CMD_SPLITTER: &str = " "; -pub static MSG_TITLE: &str = "Info"; +pub static MSG_TITLE_ERROR: &str = "Error"; pub static COMMIT_TITLE: &str = "Commit"; pub static COMMIT_MSG: &str = "type commit message.."; pub static RESET_TITLE: &str = "Reset"; diff --git a/src/ui/style.rs b/src/ui/style.rs index 22e700f6..4fc8a8b8 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -139,7 +139,7 @@ impl Theme { } pub fn text_danger(&self) -> Style { - Style::default().fg(self.diff_file_removed) + Style::default().fg(self.diff_line_delete) } pub fn toolbar(&self, enabled: bool) -> Style {