make msgbox error msgs only for now

This commit is contained in:
Stephan Dilly 2020-05-20 11:29:11 +02:00
parent 25c07a839c
commit f03a1ac611
6 changed files with 38 additions and 22 deletions

View File

@ -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);
}

View File

@ -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
)),

View File

@ -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<B: Backend>(&mut self, f: &mut Frame<B>, _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();

View File

@ -30,7 +30,7 @@ pub enum InternalEvent {
///
AddHunk(u64),
///
ShowMsg(String),
ShowErrorMsg(String),
///
Update(NeedsUpdate),
///

View File

@ -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";

View File

@ -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 {