@@ -2,36 +2,45 @@ use super::{
2
2
visibility_blocking, CommandBlocking , CommandInfo , Component ,
3
3
DrawableComponent ,
4
4
} ;
5
- use crate :: { components :: dialog_paragraph , keys, strings, ui} ;
5
+ use crate :: { keys, strings, ui} ;
6
6
use crossterm:: event:: Event ;
7
7
use std:: borrow:: Cow ;
8
8
use strings:: commands;
9
9
use tui:: {
10
10
backend:: Backend ,
11
- layout:: Rect ,
12
- widgets:: { Clear , Text } ,
11
+ layout:: { Alignment , Rect } ,
12
+ widgets:: { Block , Borders , Clear , Paragraph , Text } ,
13
13
Frame ,
14
14
} ;
15
+ use ui:: style:: Theme ;
15
16
16
- #[ derive( Default ) ]
17
17
pub struct MsgComponent {
18
18
msg : String ,
19
19
visible : bool ,
20
+ theme : Theme ,
20
21
}
21
22
22
23
impl DrawableComponent for MsgComponent {
23
24
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 ;
34
27
}
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
+ ) ;
35
44
}
36
45
}
37
46
@@ -78,6 +87,13 @@ impl Component for MsgComponent {
78
87
}
79
88
80
89
impl MsgComponent {
90
+ pub fn new ( theme : & Theme ) -> Self {
91
+ Self {
92
+ msg : String :: new ( ) ,
93
+ visible : false ,
94
+ theme : * theme,
95
+ }
96
+ }
81
97
///
82
98
pub fn show_msg ( & mut self , msg : & str ) {
83
99
self . msg = msg. to_string ( ) ;
0 commit comments