Skip to content

Commit f03a1ac

Browse files
author
Stephan Dilly
committed
make msgbox error msgs only for now
1 parent 25c07a8 commit f03a1ac

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl App {
5656
do_quit: false,
5757
current_commands: Vec::new(),
5858
help: HelpComponent::new(&theme),
59-
msg: MsgComponent::default(),
59+
msg: MsgComponent::new(&theme),
6060
tab: 0,
6161
revlog: Revlog::new(&sender, &theme),
6262
status_tab: Status::new(&sender, &queue, &theme),
@@ -263,7 +263,7 @@ impl App {
263263
}
264264
}
265265
}
266-
InternalEvent::ShowMsg(msg) => {
266+
InternalEvent::ShowErrorMsg(msg) => {
267267
self.msg.show_msg(msg.as_str());
268268
flags.insert(NeedsUpdate::ALL);
269269
}

src/components/commit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl CommitComponent {
127127
{
128128
error!("commit-msg hook error: {}", e);
129129
self.queue.borrow_mut().push_back(
130-
InternalEvent::ShowMsg(format!(
130+
InternalEvent::ShowErrorMsg(format!(
131131
"commit-msg hook error:\n{}",
132132
e
133133
)),
@@ -138,7 +138,7 @@ impl CommitComponent {
138138
if let Err(e) = sync::commit(CWD, &self.msg) {
139139
error!("commit error: {}", &e);
140140
self.queue.borrow_mut().push_back(
141-
InternalEvent::ShowMsg(format!(
141+
InternalEvent::ShowErrorMsg(format!(
142142
"commit failed:\n{}",
143143
&e
144144
)),
@@ -151,7 +151,7 @@ impl CommitComponent {
151151
{
152152
error!("post-commit hook error: {}", e);
153153
self.queue.borrow_mut().push_back(
154-
InternalEvent::ShowMsg(format!(
154+
InternalEvent::ShowErrorMsg(format!(
155155
"post-commit hook error:\n{}",
156156
e
157157
)),

src/components/msg.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,45 @@ use super::{
22
visibility_blocking, CommandBlocking, CommandInfo, Component,
33
DrawableComponent,
44
};
5-
use crate::{components::dialog_paragraph, keys, strings, ui};
5+
use crate::{keys, strings, ui};
66
use crossterm::event::Event;
77
use std::borrow::Cow;
88
use strings::commands;
99
use tui::{
1010
backend::Backend,
11-
layout::Rect,
12-
widgets::{Clear, Text},
11+
layout::{Alignment, Rect},
12+
widgets::{Block, Borders, Clear, Paragraph, Text},
1313
Frame,
1414
};
15+
use ui::style::Theme;
1516

16-
#[derive(Default)]
1717
pub struct MsgComponent {
1818
msg: String,
1919
visible: bool,
20+
theme: Theme,
2021
}
2122

2223
impl DrawableComponent for MsgComponent {
2324
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
24-
if self.visible {
25-
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
26-
27-
let area = ui::centered_rect_absolute(65, 25, f.size());
28-
f.render_widget(Clear, area);
29-
f.render_widget(
30-
dialog_paragraph(strings::MSG_TITLE, txt.iter())
31-
.wrap(true),
32-
area,
33-
);
25+
if !self.visible {
26+
return;
3427
}
28+
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
29+
30+
let area = ui::centered_rect_absolute(65, 25, f.size());
31+
f.render_widget(Clear, area);
32+
f.render_widget(
33+
Paragraph::new(txt.iter())
34+
.block(
35+
Block::default()
36+
.title(strings::MSG_TITLE_ERROR)
37+
.title_style(self.theme.text_danger())
38+
.borders(Borders::ALL),
39+
)
40+
.alignment(Alignment::Left)
41+
.wrap(true),
42+
area,
43+
);
3544
}
3645
}
3746

@@ -78,6 +87,13 @@ impl Component for MsgComponent {
7887
}
7988

8089
impl MsgComponent {
90+
pub fn new(theme: &Theme) -> Self {
91+
Self {
92+
msg: String::new(),
93+
visible: false,
94+
theme: *theme,
95+
}
96+
}
8197
///
8298
pub fn show_msg(&mut self, msg: &str) {
8399
self.msg = msg.to_string();

src/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum InternalEvent {
3030
///
3131
AddHunk(u64),
3232
///
33-
ShowMsg(String),
33+
ShowErrorMsg(String),
3434
///
3535
Update(NeedsUpdate),
3636
///

src/strings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub static TAB_DIVIDER: &str = " | ";
88

99
pub static CMD_SPLITTER: &str = " ";
1010

11-
pub static MSG_TITLE: &str = "Info";
11+
pub static MSG_TITLE_ERROR: &str = "Error";
1212
pub static COMMIT_TITLE: &str = "Commit";
1313
pub static COMMIT_MSG: &str = "type commit message..";
1414
pub static RESET_TITLE: &str = "Reset";

src/ui/style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Theme {
139139
}
140140

141141
pub fn text_danger(&self) -> Style {
142-
Style::default().fg(self.diff_file_removed)
142+
Style::default().fg(self.diff_line_delete)
143143
}
144144

145145
pub fn toolbar(&self, enabled: bool) -> Style {

0 commit comments

Comments
 (0)