@@ -10,8 +10,6 @@ import (
1010 "path/filepath"
1111 "strings"
1212
13- "github.com/AlecAivazis/survey/v2"
14- "github.com/AlecAivazis/survey/v2/terminal"
1513 "github.com/containerd/containerd/identifiers"
1614 "github.com/lima-vm/lima/cmd/limactl/editflags"
1715 "github.com/lima-vm/lima/cmd/limactl/guessarg"
@@ -24,6 +22,7 @@ import (
2422 "github.com/lima-vm/lima/pkg/store"
2523 "github.com/lima-vm/lima/pkg/store/filenames"
2624 "github.com/lima-vm/lima/pkg/templatestore"
25+ "github.com/lima-vm/lima/pkg/uiutil"
2726 "github.com/lima-vm/lima/pkg/yqutil"
2827 "github.com/sirupsen/logrus"
2928 "github.com/spf13/cobra"
@@ -366,27 +365,25 @@ func chooseNextCreatorState(st *creatorState, yq string) (*creatorState, error)
366365 logrus .WithError (err ).Warn ("Failed to evaluate yq expression" )
367366 return st , err
368367 }
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" ,
378374 }
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 {
381378 logrus .Fatal ("Interrupted by user" )
382379 }
383380 logrus .WithError (err ).Warn ("Failed to open TUI" )
384381 return st , nil
385382 }
386383 switch ans {
387- case prompt . Options [ 0 ] : // "Proceed with the current configuration"
384+ case 0 : // "Proceed with the current configuration"
388385 return st , nil
389- case prompt . Options [ 1 ] : // "Open an editor ..."
386+ case 1 : // "Open an editor ..."
390387 hdr := fmt .Sprintf ("# Review and modify the following configuration for Lima instance %q.\n " , st .instName )
391388 if st .instName == DefaultInstanceName {
392389 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)
405402 return st , errors .New ("should not reach here" )
406403 }
407404 return st , nil
408- case prompt . Options [ 2 ] : // "Choose another template..."
405+ case 2 : // "Choose another template..."
409406 templates , err := templatestore .Templates ()
410407 if err != nil {
411408 return st , err
412409 }
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 ))
418412 for i := range templates {
419- promptEx . Options [i ] = templates [i ].Name
413+ options [i ] = templates [i ].Name
420414 }
421- if err := survey .AskOne (promptEx , & ansEx ); err != nil {
415+ ansEx , err := uiutil .Select (message , options )
416+ if err != nil {
422417 return st , err
423418 }
424419 if ansEx > len (templates )- 1 {
@@ -436,7 +431,7 @@ func chooseNextCreatorState(st *creatorState, yq string) (*creatorState, error)
436431 return nil , err
437432 }
438433 continue
439- case prompt . Options [ 3 ] : // "Exit"
434+ case 3 : // "Exit"
440435 os .Exit (0 )
441436 return st , errors .New ("should not reach here" )
442437 default :
0 commit comments