@@ -179,31 +179,33 @@ func (m selectModel) View() string {
179
179
180
180
msg := pretty .Sprintf (pretty .Bold (), "? %s" , m .message )
181
181
182
- if m .selected == "" {
183
- if m .hideSearch {
184
- s += fmt .Sprintf ("%s [Use arrows to move]\n " , msg )
185
- } else {
186
- s += fmt .Sprintf ("%s %s[Use arrows to move, type to filter]\n " , msg , m .search .View ())
187
- }
182
+ if m .selected != "" {
183
+ selected := pretty .Sprint (DefaultStyles .Keyword , m .selected )
184
+ s += fmt .Sprintf ("%s %s\n " , msg , selected )
188
185
189
- options , start := m .viewableOptions ()
186
+ return s
187
+ }
190
188
191
- for i , option := range options {
192
- // Is this the currently selected option?
193
- style := pretty .Wrap (" " , "" )
194
- if m .cursor == start + i {
195
- style = pretty.Style {
196
- pretty .Wrap ("> " , "" ),
197
- pretty .FgColor (Green ),
198
- }
199
- }
189
+ if m .hideSearch {
190
+ s += fmt .Sprintf ("%s [Use arrows to move]\n " , msg )
191
+ } else {
192
+ s += fmt .Sprintf ("%s %s[Use arrows to move, type to filter]\n " , msg , m .search .View ())
193
+ }
194
+
195
+ options , start := m .viewableOptions ()
200
196
201
- s += pretty .Sprint (style , option )
202
- s += "\n "
197
+ for i , option := range options {
198
+ // Is this the currently selected option?
199
+ style := pretty .Wrap (" " , "" )
200
+ if m .cursor == start + i {
201
+ style = pretty.Style {
202
+ pretty .Wrap ("> " , "" ),
203
+ pretty .FgColor (Green ),
204
+ }
203
205
}
204
- } else {
205
- selected : = pretty .Sprint (DefaultStyles . Keyword , m . selected )
206
- s += fmt . Sprintf ( "%s %s \n ", msg , selected )
206
+
207
+ s + = pretty .Sprint (style , option )
208
+ s += " \n "
207
209
}
208
210
209
211
return s
@@ -259,6 +261,7 @@ func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, er
259
261
for _ , d := range opts .Defaults {
260
262
if option == d {
261
263
chosen = true
264
+ break
262
265
}
263
266
}
264
267
@@ -353,7 +356,7 @@ func (m multiSelectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
353
356
case tea .KeyRight :
354
357
options := m .filteredOptions ()
355
358
for _ , option := range options {
356
- option .chosen = false
359
+ option .chosen = true
357
360
}
358
361
359
362
case tea .KeyLeft :
@@ -381,42 +384,47 @@ func (m multiSelectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
381
384
}
382
385
383
386
func (m multiSelectModel ) View () string {
384
- var s string
387
+ var s strings. Builder
385
388
386
389
msg := pretty .Sprintf (pretty .Bold (), "? %s" , m .message )
387
390
388
- if ! m .selected {
389
- s += fmt .Sprintf ("%s %s[Use arrows to move, space to select, <right> to all, <left> to none, type to filter]\n " , msg , m .search .View ())
390
-
391
- for i , option := range m .filteredOptions () {
392
- cursor := " "
393
- chosen := "[ ]"
394
- o := option .option
391
+ if m .selected {
392
+ selected := pretty .Sprint (DefaultStyles .Keyword , strings .Join (m .selectedOptions (), ", " ))
393
+ _ , _ = s .WriteString (fmt .Sprintf ("%s %s\n " , msg , selected ))
395
394
396
- if m .cursor == i {
397
- cursor = pretty .Sprint (pretty .FgColor (Green ), "> " )
398
- chosen = pretty .Sprint (pretty .FgColor (Green ), "[ ]" )
399
- o = pretty .Sprint (pretty .FgColor (Green ), o )
400
- }
395
+ return s .String ()
396
+ }
401
397
402
- if option .chosen {
403
- chosen = pretty .Sprint (pretty .FgColor (Green ), "[x]" )
404
- }
398
+ _ , _ = s .WriteString (fmt .Sprintf (
399
+ "%s %s[Use arrows to move, space to select, <right> to all, <left> to none, type to filter]\n " ,
400
+ msg ,
401
+ m .search .View (),
402
+ ))
403
+
404
+ for i , option := range m .filteredOptions () {
405
+ cursor := " "
406
+ chosen := "[ ]"
407
+ o := option .option
408
+
409
+ if m .cursor == i {
410
+ cursor = pretty .Sprint (pretty .FgColor (Green ), "> " )
411
+ chosen = pretty .Sprint (pretty .FgColor (Green ), "[ ]" )
412
+ o = pretty .Sprint (pretty .FgColor (Green ), o )
413
+ }
405
414
406
- s += fmt .Sprintf (
407
- "%s%s %s\n " ,
408
- cursor ,
409
- chosen ,
410
- o ,
411
- )
415
+ if option .chosen {
416
+ chosen = pretty .Sprint (pretty .FgColor (Green ), "[x]" )
412
417
}
413
- } else {
414
- selected := pretty .Sprint (DefaultStyles .Keyword , strings .Join (m .selectedOptions (), ", " ))
415
418
416
- s += fmt .Sprintf ("%s %s\n " , msg , selected )
419
+ _ , _ = s .WriteString (fmt .Sprintf (
420
+ "%s%s %s\n " ,
421
+ cursor ,
422
+ chosen ,
423
+ o ,
424
+ ))
417
425
}
418
426
419
- return s
427
+ return s . String ()
420
428
}
421
429
422
430
func (m multiSelectModel ) filteredOptions () []* multiSelectOption {
0 commit comments