@@ -39,6 +39,20 @@ func Checkbox(label string, checked bool) string {
39
39
return fmt .Sprintf ("[ ] %s" , label )
40
40
}
41
41
42
+ // ToggleWidget represents a toggle.
43
+ func ToggleWidget (label string , now , enabled bool ) string {
44
+ if now {
45
+ if enabled {
46
+ return ColorFg ("▶ [x] " + label , "212" )
47
+ }
48
+ return ColorFg ("▶ [ ] " + label , "212" )
49
+ }
50
+ if enabled {
51
+ return ColorFg (" [x] " + label , "212" )
52
+ }
53
+ return fmt .Sprintf (" [ ] %s" , label )
54
+ }
55
+
42
56
// Split splits a string into multiple lines.
43
57
// Each line has a maximum length of 80 characters.
44
58
func Split (s string ) []string {
@@ -103,3 +117,32 @@ func (c *Choice) Decrement() {
103
117
c .Choice = c .Max
104
118
}
105
119
}
120
+
121
+ // Toggle represents a toggle.
122
+ type Toggle struct {
123
+ Enabled bool
124
+ }
125
+
126
+ // NewToggle returns a new toggle.
127
+ func NewToggle () * Toggle {
128
+ return & Toggle {
129
+ Enabled : false ,
130
+ }
131
+ }
132
+
133
+ // Toggle toggles the toggle.
134
+ func (t * Toggle ) Toggle () {
135
+ t .Enabled = ! t .Enabled
136
+ }
137
+
138
+ // ToggleSets represents a set of toggles.
139
+ type ToggleSets []* Toggle
140
+
141
+ // NewToggleSets returns a new toggle sets.
142
+ func NewToggleSets (n int ) ToggleSets {
143
+ ts := make ([]* Toggle , 0 , n )
144
+ for i := 0 ; i < n ; i ++ {
145
+ ts = append (ts , NewToggle ())
146
+ }
147
+ return ts
148
+ }
0 commit comments