@@ -15,6 +15,7 @@ import (
1515// helpDialog displays all currently active key bindings in a scrollable dialog.
1616type helpDialog struct {
1717 readOnlyScrollDialog
18+
1819 bindings []key.Binding
1920}
2021
@@ -61,65 +62,72 @@ func (d *helpDialog) renderContent(contentWidth, maxHeight int) []string {
6162 continue
6263 }
6364 keyStr := binding .Keys ()[0 ]
64- if strings .HasPrefix (keyStr , "ctrl+" ) {
65+ switch {
66+ case strings .HasPrefix (keyStr , "ctrl+" ):
6567 ctrlBindings = append (ctrlBindings , binding )
66- } else if keyStr == "esc" || keyStr == "enter" || keyStr == "tab" {
68+ case keyStr == "esc" || keyStr == "enter" || keyStr == "tab" :
6769 globalBindings = append (globalBindings , binding )
68- } else {
70+ default :
6971 otherBindings = append (otherBindings , binding )
7072 }
7173 }
7274
7375 // Render global bindings
7476 if len (globalBindings ) > 0 {
75- lines = append (lines , styles .DialogHelpStyle .Bold (true ).Render ("General" ))
76- lines = append (lines , "" )
77+ lines = append (lines ,
78+ styles .DialogHelpStyle .Bold (true ).Render ("General" ),
79+ "" ,
80+ )
7781 for _ , binding := range globalBindings {
78- lines = append (lines , d .formatBinding (binding , keyStyle , descStyle , contentWidth ))
82+ lines = append (lines , d .formatBinding (binding , keyStyle , descStyle ))
7983 }
8084 lines = append (lines , "" )
8185 }
8286
8387 // Render ctrl bindings
8488 if len (ctrlBindings ) > 0 {
85- lines = append (lines , styles .DialogHelpStyle .Bold (true ).Render ("Control Key Shortcuts" ))
86- lines = append (lines , "" )
89+ lines = append (lines ,
90+ styles .DialogHelpStyle .Bold (true ).Render ("Control Key Shortcuts" ),
91+ "" ,
92+ )
8793 for _ , binding := range ctrlBindings {
88- lines = append (lines , d .formatBinding (binding , keyStyle , descStyle , contentWidth ))
94+ lines = append (lines , d .formatBinding (binding , keyStyle , descStyle ))
8995 }
9096 lines = append (lines , "" )
9197 }
9298
9399 // Render other bindings
94100 if len (otherBindings ) > 0 {
95- lines = append (lines , styles .DialogHelpStyle .Bold (true ).Render ("Other" ))
96- lines = append (lines , "" )
101+ lines = append (lines ,
102+ styles .DialogHelpStyle .Bold (true ).Render ("Other" ),
103+ "" ,
104+ )
97105 for _ , binding := range otherBindings {
98- lines = append (lines , d .formatBinding (binding , keyStyle , descStyle , contentWidth ))
106+ lines = append (lines , d .formatBinding (binding , keyStyle , descStyle ))
99107 }
100108 }
101109
102110 return lines
103111}
104112
105113// formatBinding formats a single key binding as " key description"
106- func (d * helpDialog ) formatBinding (binding key.Binding , keyStyle , descStyle lipgloss.Style , width int ) string {
114+ func (d * helpDialog ) formatBinding (binding key.Binding , keyStyle , descStyle lipgloss.Style ) string {
107115 helpInfo := binding .Help ()
108116 helpKey := helpInfo .Key
109117 helpDesc := helpInfo .Desc
110-
118+
111119 // Calculate spacing to align descriptions
112120 const keyWidth = 20
113121 const indent = 2
114-
122+
115123 keyPart := keyStyle .Render (helpKey )
116124 descPart := descStyle .Render (helpDesc )
117-
125+
118126 // Pad the key part to align descriptions
119127 keyPartWidth := lipgloss .Width (keyPart )
120128 padding := strings .Repeat (" " , max (1 , keyWidth - keyPartWidth ))
121-
122- return fmt .Sprintf ("%s%s%s%s" ,
129+
130+ return fmt .Sprintf ("%s%s%s%s" ,
123131 strings .Repeat (" " , indent ),
124132 keyPart ,
125133 padding ,
@@ -133,10 +141,8 @@ func (d *helpDialog) Init() tea.Cmd {
133141
134142func (d * helpDialog ) Update (msg tea.Msg ) (layout.Model , tea.Cmd ) {
135143 model , cmd := d .readOnlyScrollDialog .Update (msg )
136- if model != nil {
137- if rod , ok := model .(* readOnlyScrollDialog ); ok {
138- d .readOnlyScrollDialog = * rod
139- }
144+ if rod , ok := model .(* readOnlyScrollDialog ); ok {
145+ d .readOnlyScrollDialog = * rod
140146 }
141147 return d , cmd
142148}
0 commit comments