@@ -33,7 +33,8 @@ pub struct Describe {
3333 pub keymap : HashMap < KeyEvent , Action > ,
3434 pub text : Vec < String > ,
3535 pub last_events : Vec < KeyEvent > ,
36- wrap : bool ,
36+ title : Option < String > ,
37+ is_focused : bool ,
3738 max_row_length : u16 ,
3839 content_scroll : ( u16 , u16 ) ,
3940 content_size : Size ,
@@ -43,7 +44,10 @@ pub struct Describe {
4344
4445impl Describe {
4546 pub fn new ( ) -> Self {
46- Self :: default ( )
47+ Self {
48+ is_focused : true ,
49+ ..Default :: default ( )
50+ }
4751 }
4852
4953 pub fn keymap ( mut self , keymap : HashMap < KeyEvent , Action > ) -> Self {
@@ -57,11 +61,11 @@ impl Describe {
5761
5862 pub fn render_tick ( & mut self ) { }
5963
60- fn set_data ( & mut self , data : Value ) -> Result < ( ) > {
64+ pub fn set_data ( & mut self , data : Value ) -> Result < ( ) > {
6165 if data. is_string ( ) {
6266 self . text = data
6367 . as_str ( )
64- . ok_or_eyre ( "Cannot treat data as string" ) ?
68+ . ok_or_eyre ( "Cannot access data as string" ) ?
6569 . split ( "\n " )
6670 . map ( String :: from)
6771 . collect :: < Vec < _ > > ( ) ;
@@ -87,6 +91,16 @@ impl Describe {
8791 Ok ( ( ) )
8892 }
8993
94+ pub fn set_title ( & mut self , title : Option < String > ) -> Result < ( ) > {
95+ self . title = title;
96+ Ok ( ( ) )
97+ }
98+
99+ pub fn set_focus ( & mut self , focus : bool ) -> Result < ( ) > {
100+ self . is_focused = focus;
101+ Ok ( ( ) )
102+ }
103+
90104 pub fn cursor_up ( & mut self ) -> Result < ( ) > {
91105 if self . text . len ( ) as u16 > self . content_size . height {
92106 self . content_scroll . 0 = self . content_scroll . 0 . saturating_sub ( 1 ) ;
@@ -165,10 +179,21 @@ impl Describe {
165179
166180 fn render ( & mut self , f : & mut Frame < ' _ > , area : Rect ) {
167181 let block = Block :: default ( )
168- . title ( Title :: from ( " Describe " ) . alignment ( Alignment :: Center ) )
182+ . title (
183+ Title :: from ( self . title . clone ( ) . unwrap_or ( String :: from ( " Describe " ) ) )
184+ . alignment ( Alignment :: Center ) ,
185+ )
186+ . title_style ( match self . is_focused {
187+ true => Style :: new ( ) . white ( ) ,
188+ false => Style :: default ( ) ,
189+ } )
169190 . borders ( Borders :: ALL )
170191 . padding ( Padding :: horizontal ( 1 ) )
171- . border_style ( Style :: default ( ) . fg ( PALETTES [ 0 ] . c900 ) ) ;
192+ . border_style ( Style :: default ( ) . fg ( PALETTES [ 0 ] . c900 ) )
193+ . style ( match self . is_focused {
194+ true => Style :: new ( ) ,
195+ false => Style :: new ( ) . gray ( ) ,
196+ } ) ;
172197 self . content_size = block. inner ( area) . as_size ( ) ;
173198
174199 let text: Vec < Line > = self . text . clone ( ) . into_iter ( ) . map ( Line :: from) . collect ( ) ;
0 commit comments