Skip to content

Commit b0a4bae

Browse files
committed
Fix linter issues
- Add blank line after embedded field (embeddedstructfieldcheck) - Use switch instead of if-else chain (gocritic) - Combine append chains (gocritic) - Fix variable shadowing of 'key' import (gocritic) - Remove nil check that's always true (staticcheck) - Remove unused width parameter (unparam) - Fix imports formatting (gci) Assisted-By: docker-agent
1 parent 2f3ef93 commit b0a4bae

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

pkg/tui/dialog/help.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
// helpDialog displays all currently active key bindings in a scrollable dialog.
1616
type 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

134142
func (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
}

pkg/tui/tui.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ func (m *appModel) AllBindings() []key.Binding {
16551655
// This filters AllBindings() to show only the most essential commands.
16561656
func (m *appModel) Bindings() []key.Binding {
16571657
all := m.AllBindings()
1658-
1658+
16591659
// Define which keys should appear in the status bar
16601660
statusBarKeys := map[string]bool{
16611661
"ctrl+c": true, // quit
@@ -1671,24 +1671,24 @@ func (m *appModel) Bindings() []key.Binding {
16711671
"ctrl+g": true, // edit in external editor (editor context)
16721672
"ctrl+r": true, // history search (editor context)
16731673
// Content panel bindings (↑↓, c, e, d) are always included
1674-
"up": true,
1675-
"down": true,
1676-
"c": true,
1677-
"e": true,
1678-
"d": true,
1674+
"up": true,
1675+
"down": true,
1676+
"c": true,
1677+
"e": true,
1678+
"d": true,
16791679
}
1680-
1680+
16811681
// Filter to only include status bar keys
16821682
var filtered []key.Binding
16831683
for _, binding := range all {
16841684
if len(binding.Keys()) > 0 {
1685-
key := binding.Keys()[0]
1686-
if statusBarKeys[key] {
1685+
bindingKey := binding.Keys()[0]
1686+
if statusBarKeys[bindingKey] {
16871687
filtered = append(filtered, binding)
16881688
}
16891689
}
16901690
}
1691-
1691+
16921692
return filtered
16931693
}
16941694

0 commit comments

Comments
 (0)