@@ -10,8 +10,6 @@ import (
10
10
"path/filepath"
11
11
"strings"
12
12
13
- "github.com/AlecAivazis/survey/v2"
14
- "github.com/AlecAivazis/survey/v2/terminal"
15
13
"github.com/containerd/containerd/identifiers"
16
14
"github.com/lima-vm/lima/cmd/limactl/editflags"
17
15
"github.com/lima-vm/lima/cmd/limactl/guessarg"
@@ -24,6 +22,7 @@ import (
24
22
"github.com/lima-vm/lima/pkg/store"
25
23
"github.com/lima-vm/lima/pkg/store/filenames"
26
24
"github.com/lima-vm/lima/pkg/templatestore"
25
+ "github.com/lima-vm/lima/pkg/uiutil"
27
26
"github.com/lima-vm/lima/pkg/yqutil"
28
27
"github.com/sirupsen/logrus"
29
28
"github.com/spf13/cobra"
@@ -366,27 +365,25 @@ func chooseNextCreatorState(st *creatorState, yq string) (*creatorState, error)
366
365
logrus .WithError (err ).Warn ("Failed to evaluate yq expression" )
367
366
return st , err
368
367
}
369
- var ans string
370
- prompt := & survey.Select {
371
- Message : fmt .Sprintf ("Creating an instance %q" , st .instName ),
372
- Options : []string {
373
- "Proceed with the current configuration" ,
374
- "Open an editor to review or modify the current configuration" ,
375
- "Choose another template (docker, podman, archlinux, fedora, ...)" ,
376
- "Exit" ,
377
- },
368
+ message := fmt .Sprintf ("Creating an instance %q" , st .instName )
369
+ options := []string {
370
+ "Proceed with the current configuration" ,
371
+ "Open an editor to review or modify the current configuration" ,
372
+ "Choose another template (docker, podman, archlinux, fedora, ...)" ,
373
+ "Exit" ,
378
374
}
379
- if err := survey .AskOne (prompt , & ans ); err != nil {
380
- if err == terminal .InterruptErr {
375
+ ans , err := uiutil .Select (message , options )
376
+ if err != nil {
377
+ if err == uiutil .InterruptErr {
381
378
logrus .Fatal ("Interrupted by user" )
382
379
}
383
380
logrus .WithError (err ).Warn ("Failed to open TUI" )
384
381
return st , nil
385
382
}
386
383
switch ans {
387
- case prompt . Options [ 0 ] : // "Proceed with the current configuration"
384
+ case 0 : // "Proceed with the current configuration"
388
385
return st , nil
389
- case prompt . Options [ 1 ] : // "Open an editor ..."
386
+ case 1 : // "Open an editor ..."
390
387
hdr := fmt .Sprintf ("# Review and modify the following configuration for Lima instance %q.\n " , st .instName )
391
388
if st .instName == DefaultInstanceName {
392
389
hdr += "# - In most cases, you do not need to modify this file.\n "
@@ -405,20 +402,18 @@ func chooseNextCreatorState(st *creatorState, yq string) (*creatorState, error)
405
402
return st , errors .New ("should not reach here" )
406
403
}
407
404
return st , nil
408
- case prompt . Options [ 2 ] : // "Choose another template..."
405
+ case 2 : // "Choose another template..."
409
406
templates , err := templatestore .Templates ()
410
407
if err != nil {
411
408
return st , err
412
409
}
413
- var ansEx int
414
- promptEx := & survey.Select {
415
- Message : "Choose a template" ,
416
- Options : make ([]string , len (templates )),
417
- }
410
+ message := "Choose a template"
411
+ options := make ([]string , len (templates ))
418
412
for i := range templates {
419
- promptEx . Options [i ] = templates [i ].Name
413
+ options [i ] = templates [i ].Name
420
414
}
421
- if err := survey .AskOne (promptEx , & ansEx ); err != nil {
415
+ ansEx , err := uiutil .Select (message , options )
416
+ if err != nil {
422
417
return st , err
423
418
}
424
419
if ansEx > len (templates )- 1 {
@@ -436,7 +431,7 @@ func chooseNextCreatorState(st *creatorState, yq string) (*creatorState, error)
436
431
return nil , err
437
432
}
438
433
continue
439
- case prompt . Options [ 3 ] : // "Exit"
434
+ case 3 : // "Exit"
440
435
os .Exit (0 )
441
436
return st , errors .New ("should not reach here" )
442
437
default :
0 commit comments