@@ -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} ;
66use crossterm:: event:: Event ;
77use std:: borrow:: Cow ;
88use strings:: commands;
99use 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 ) ]
1717pub struct MsgComponent {
1818 msg : String ,
1919 visible : bool ,
20+ theme : Theme ,
2021}
2122
2223impl 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
8089impl 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 ( ) ;
0 commit comments