@@ -37,11 +37,113 @@ var (
37
37
Deselect = fmt .Sprintf (" %s %s %s\n " , Press , DeselectKey , ToDeselect )
38
38
)
39
39
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
+
41
121
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
45
126
}
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
+
46
148
return s
47
149
}
0 commit comments