diff --git a/internal/app/app.go b/internal/app/app.go index 24de609..5d3053c 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -102,7 +102,7 @@ func (a *App) getAction() func(c *cli.Context) error { return err } - regionsLabel := "Select regions you want to search.\n" + regionsLabel := []string{"Select regions you want to search."} targetRegions, continuation, err := io.GetCheckboxes(regionsLabel, allRegions) if err != nil { return err @@ -111,7 +111,7 @@ func (a *App) getAction() func(c *cli.Context) error { return nil } - runtimeLabel := "Select runtime values you want to search.\n" + runtimeLabel := []string{"Select runtime values you want to search."} targetRuntime, continuation, err := io.GetCheckboxes(runtimeLabel, allRuntime) if err != nil { return err diff --git a/internal/io/input.go b/internal/io/input.go index 0a33933..6b03b8c 100644 --- a/internal/io/input.go +++ b/internal/io/input.go @@ -10,18 +10,18 @@ import ( "github.com/fatih/color" ) -func GetCheckboxes(header string, opts []string) ([]string, bool, error) { +func GetCheckboxes(headers []string, opts []string) ([]string, bool, error) { for { - ui := NewUI(opts, header) + ui := NewUI(opts, headers) p := tea.NewProgram(ui) if _, err := p.Run(); err != nil { return nil, false, err } - var checkboxes []string + checkboxes := []string{} for c := range ui.Choices { if _, ok := ui.Selected[c]; ok { - checkboxes = append(checkboxes, opts[c]) + checkboxes = append(checkboxes, ui.Choices[c]) } } diff --git a/internal/io/ui.go b/internal/io/ui.go index 76c198a..01b6e10 100644 --- a/internal/io/ui.go +++ b/internal/io/ui.go @@ -10,7 +10,7 @@ import ( type UI struct { Choices []string - Header string + Headers []string Cursor int Selected map[int]struct{} Keyword string @@ -19,10 +19,10 @@ type UI struct { var _ tea.Model = (*UI)(nil) -func NewUI(choices []string, header string) *UI { +func NewUI(choices []string, headers []string) *UI { return &UI{ Choices: choices, - Header: header, + Headers: headers, Selected: make(map[int]struct{}), } } @@ -99,7 +99,11 @@ func (u *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (u *UI) View() string { - s := color.CyanString("? ") + color.New(color.Bold).Sprint(u.Header) + s := color.CyanString("? ") + + for _, header := range u.Headers { + s += color.New(color.Bold).Sprintln(header) + } if u.isEntered { return s @@ -111,8 +115,12 @@ func (u *UI) View() string { s += "\n" for i, choice := range u.Choices { - if u.Keyword != "" && !strings.Contains(choice, u.Keyword) { - continue + if u.Keyword != "" { + lk := strings.ToLower(u.Keyword) + lc := strings.ToLower(choice) + if !strings.Contains(lc, lk) { + continue + } } cursor := " " // no cursor