Skip to content

Commit 56aa4ab

Browse files
committed
refactor(ui): enhance keyboard help configuration
- Introduce functional options for configuring keyboard help. - Replace boolean flag with more flexible option pattern. - Update UI components to use new keyboard help options. [Generated by Kommit]
1 parent a338683 commit 56aa4ab

File tree

5 files changed

+113
-8
lines changed

5 files changed

+113
-8
lines changed

internal/ui/commit_selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (m *CommitSelector) View() string {
8888
s += fmt.Sprintf("%s %s\n", cursor, style.Render(choice))
8989
}
9090

91-
return WrapWithKeyboardHelp(s, false)
91+
return WrapWithKeyboardHelp(s, WithStandardNavigation())
9292
}
9393

9494
func SelectCommit() (CommitOption, error) {

internal/ui/cost_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3434
func (m Model) View() string {
3535
s := TitleStyle.Render("💰 Kommit Financial Therapy Session 💰") +
3636
"\n\n" + m.table.View() + "\n"
37-
return WrapWithKeyboardHelp(s, false)
37+
return WrapWithKeyboardHelp(s, WithBasicNavigation())
3838
}
3939

4040
func NewTableModel(costs utils.Costs) Model {

internal/ui/keyboard_help.go

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,113 @@ var (
3737
Deselect = fmt.Sprintf(" %s %s %s\n", Press, DeselectKey, ToDeselect)
3838
)
3939

40-
func WrapWithKeyboardHelp(s string, isSelect bool) string {
40+
type HelpOption func(*helpConfig)
41+
type helpConfig struct {
42+
showNavigate bool
43+
showProceed bool
44+
showExit bool
45+
showToggle bool
46+
showSelect bool
47+
showDeselect bool
48+
}
49+
50+
func WithNavigation() HelpOption {
51+
return func(c *helpConfig) {
52+
c.showNavigate = true
53+
}
54+
}
55+
56+
func WithProceed() HelpOption {
57+
return func(c *helpConfig) {
58+
c.showProceed = true
59+
}
60+
}
61+
62+
func WithExit() HelpOption {
63+
return func(c *helpConfig) {
64+
c.showExit = true
65+
}
66+
}
67+
68+
func WithToggle() HelpOption {
69+
return func(c *helpConfig) {
70+
c.showToggle = true
71+
}
72+
}
73+
74+
func WithSelect() HelpOption {
75+
return func(c *helpConfig) {
76+
c.showSelect = true
77+
}
78+
}
79+
80+
func WithDeselect() HelpOption {
81+
return func(c *helpConfig) {
82+
c.showDeselect = true
83+
}
84+
}
85+
86+
func WithSelectionOptions() HelpOption {
87+
return func(c *helpConfig) {
88+
c.showToggle = true
89+
c.showSelect = true
90+
c.showDeselect = true
91+
}
92+
}
93+
94+
func WithBasicNavigation() HelpOption {
95+
return func(c *helpConfig) {
96+
c.showNavigate = true
97+
c.showExit = true
98+
}
99+
}
100+
101+
func WithStandardNavigation() HelpOption {
102+
return func(c *helpConfig) {
103+
c.showNavigate = true
104+
c.showProceed = true
105+
c.showExit = true
106+
}
107+
}
108+
109+
func WrapWithKeyboardHelp(s string, options ...HelpOption) string {
110+
// Default configuration
111+
config := &helpConfig{
112+
showNavigate: true,
113+
showExit: true,
114+
}
115+
116+
// Apply all options
117+
for _, option := range options {
118+
option(config)
119+
}
120+
41121
s += "\n\n"
42-
s += Navigate + Proceed + Exit
43-
if isSelect {
44-
s += Toggle + Select + Deselect
122+
123+
// NOTE: order of options is important
124+
if config.showNavigate {
125+
s += Navigate
45126
}
127+
128+
if config.showProceed {
129+
s += Proceed
130+
}
131+
132+
if config.showExit {
133+
s += Exit
134+
}
135+
136+
if config.showToggle {
137+
s += Toggle
138+
}
139+
140+
if config.showSelect {
141+
s += Select
142+
}
143+
144+
if config.showDeselect {
145+
s += Deselect
146+
}
147+
46148
return s
47149
}

internal/ui/model_selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (m *ModelSelector) View() string {
6464
s += cursor + " " + style.Render(choice) + "\n"
6565
}
6666

67-
return WrapWithKeyboardHelp(s, false)
67+
return WrapWithKeyboardHelp(s, WithStandardNavigation())
6868
}
6969

7070
func SelectModel() (string, error) {

internal/ui/type_selector.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ func (m *TypeSelector) View() string {
109109
s += cursor + " " + checkboxStyle.Render(checked) + " " + nameStyle.Render(item.Name) + "\n"
110110
}
111111

112-
return WrapWithKeyboardHelp(s, true)
112+
return WrapWithKeyboardHelp(s,
113+
WithStandardNavigation(),
114+
WithSelectionOptions(),
115+
)
113116
}
114117

115118
func (m *TypeSelector) GetSelectedTypes() []string {

0 commit comments

Comments
 (0)