11use crate :: common:: { PRIMARY_COLOR , TITLE , TITLE_FG_COLOR } ;
22use crate :: model:: Model ;
3+ use crate :: model:: View ;
34use ratatui:: {
5+ layout:: Alignment ,
46 style:: { Style , Stylize } ,
5- widgets:: { Block , List , ListDirection , ListItem , Padding } ,
7+ text:: Line ,
8+ widgets:: { Block , List , ListDirection , ListItem , Padding , Paragraph } ,
69 Frame ,
710} ;
811
12+ const HELP_CONTENTS : & str = include_str ! ( "static/help.txt" ) ;
13+
914pub ( crate ) fn view ( model : & mut Model , frame : & mut Frame ) {
15+ match model. view {
16+ View :: List => render_list_view ( model, frame) ,
17+ View :: Help => render_help_view ( frame) ,
18+ }
19+ }
20+
21+ fn render_list_view ( model : & mut Model , frame : & mut Frame ) {
1022 let items: Vec < ListItem > = model. lines . items . iter ( ) . map ( ListItem :: from) . collect ( ) ;
1123
1224 let title = model
@@ -20,13 +32,13 @@ pub(crate) fn view(model: &mut Model, frame: &mut Frame) {
2032 Some ( _) => base_title_style,
2133 None => base_title_style. bg ( PRIMARY_COLOR ) . fg ( TITLE_FG_COLOR ) ,
2234 } ;
35+
36+ let block = Block :: default ( )
37+ . title_bottom ( title)
38+ . title_style ( title_style) ;
39+
2340 let list = List :: new ( items)
24- . block (
25- Block :: default ( )
26- . title_bottom ( title)
27- . padding ( Padding :: bottom ( 1 ) )
28- . title_style ( title_style) ,
29- )
41+ . block ( block)
3042 . style ( Style :: new ( ) . white ( ) )
3143 . repeat_highlight_symbol ( true )
3244 . highlight_symbol ( ">> " )
@@ -35,3 +47,21 @@ pub(crate) fn view(model: &mut Model, frame: &mut Frame) {
3547
3648 frame. render_stateful_widget ( list, frame. area ( ) , & mut model. lines . state )
3749}
50+
51+ fn render_help_view ( frame : & mut Frame ) {
52+ let title_style = Style :: new ( ) . bold ( ) . bg ( PRIMARY_COLOR ) . fg ( TITLE_FG_COLOR ) ;
53+
54+ let block = Block :: default ( )
55+ . title_bottom ( TITLE )
56+ . padding ( Padding :: left ( 1 ) )
57+ . title_style ( title_style) ;
58+
59+ let lines: Vec < Line < ' _ > > = HELP_CONTENTS . lines ( ) . map ( Line :: from) . collect ( ) ;
60+
61+ let p = Paragraph :: new ( lines)
62+ . block ( block)
63+ . style ( Style :: new ( ) . white ( ) )
64+ . alignment ( Alignment :: Left ) ;
65+
66+ frame. render_widget ( p, frame. area ( ) )
67+ }
0 commit comments