@@ -10,28 +10,127 @@ use tui_world::{Keybindings, WidgetId};
1010
1111use crate :: theme:: Theme ;
1212
13- const HELP_WIDTH : u16 = 37 ;
13+ const HELP_WIDTH : u16 = 44 ;
14+
15+ struct HelpEntry {
16+ keys : & ' static str ,
17+ description : & ' static str ,
18+ }
19+
20+ struct HelpSection {
21+ title : & ' static str ,
22+ entries : & ' static [ HelpEntry ] ,
23+ }
24+
25+ const HELP_SECTIONS : & [ HelpSection ] = & [
26+ HelpSection {
27+ title : "[Navigation]" ,
28+ entries : & [
29+ HelpEntry {
30+ keys : "h/l, ←/→" ,
31+ description : "Select participant" ,
32+ } ,
33+ HelpEntry {
34+ keys : "j/k, ↓/↑" ,
35+ description : "Select message/note" ,
36+ } ,
37+ ] ,
38+ } ,
39+ HelpSection {
40+ title : "[Insert]" ,
41+ entries : & [
42+ HelpEntry {
43+ keys : "p" ,
44+ description : "Add participant" ,
45+ } ,
46+ HelpEntry {
47+ keys : "m/M" ,
48+ description : "Insert message after/before" ,
49+ } ,
50+ HelpEntry {
51+ keys : "n/N" ,
52+ description : "Insert note after/before" ,
53+ } ,
54+ ] ,
55+ } ,
56+ HelpSection {
57+ title : "[Edit]" ,
58+ entries : & [
59+ HelpEntry {
60+ keys : "e, Enter" ,
61+ description : "Edit selected" ,
62+ } ,
63+ HelpEntry {
64+ keys : "r" ,
65+ description : "Rename selected" ,
66+ } ,
67+ HelpEntry {
68+ keys : "d" ,
69+ description : "Delete selected" ,
70+ } ,
71+ HelpEntry {
72+ keys : "C" ,
73+ description : "Clear diagram" ,
74+ } ,
75+ ] ,
76+ } ,
77+ HelpSection {
78+ title : "[Move]" ,
79+ entries : & [
80+ HelpEntry {
81+ keys : "H/L, ⇧←/→" ,
82+ description : "Move participant" ,
83+ } ,
84+ HelpEntry {
85+ keys : "J/K, ⇧↓/↑" ,
86+ description : "Move message/note up/down" ,
87+ } ,
88+ ] ,
89+ } ,
90+ HelpSection {
91+ title : "[Other]" ,
92+ entries : & [
93+ HelpEntry {
94+ keys : "E" ,
95+ description : "Export to Mermaid" ,
96+ } ,
97+ HelpEntry {
98+ keys : "?" ,
99+ description : "Toggle help" ,
100+ } ,
101+ HelpEntry {
102+ keys : "Ctrl+c" ,
103+ description : "Quit" ,
104+ } ,
105+ ] ,
106+ } ,
107+ ] ;
14108
15109pub fn render_help (
16110 frame : & mut Frame ,
17111 area : Rect ,
18112 theme : & Theme ,
19- keybindings : & Keybindings ,
20- active : & [ WidgetId ] ,
113+ _keybindings : & Keybindings ,
114+ _active : & [ WidgetId ] ,
21115) {
22- let display = keybindings. display_for ( active) ;
23-
24- let lines: Vec < Line > = display
25- . iter ( )
26- . map ( |info| {
27- let keys = info. keys_display_compact ( ) ;
28- Line :: from ( vec ! [
29- Span :: styled( format!( "{keys:>9}" ) , theme. key) ,
116+ let mut lines: Vec < Line > = Vec :: new ( ) ;
117+
118+ for ( i, section) in HELP_SECTIONS . iter ( ) . enumerate ( ) {
119+ if i > 0 {
120+ lines. push ( Line :: raw ( "" ) ) ;
121+ }
122+
123+ lines. push ( Line :: from ( Span :: styled ( section. title , theme. muted ) ) ) ;
124+
125+ for entry in section. entries {
126+ let spans = vec ! [
127+ Span :: styled( format!( " {:>10}" , entry. keys) , theme. key) ,
30128 Span :: raw( " " ) ,
31- Span :: styled( info. name, theme. text) ,
32- ] )
33- } )
34- . collect ( ) ;
129+ Span :: styled( entry. description, theme. text) ,
130+ ] ;
131+ lines. push ( Line :: from ( spans) ) ;
132+ }
133+ }
35134
36135 let popup_height = ( lines. len ( ) as u16 + 2 ) . min ( area. height . saturating_sub ( 2 ) ) ;
37136
0 commit comments