Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Aug 18, 2024
1 parent a9881b2 commit 12e86d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/io/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down
20 changes: 14 additions & 6 deletions internal/io/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type UI struct {
Choices []string
Header string
Headers []string
Cursor int
Selected map[int]struct{}
Keyword string
Expand All @@ -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{}),
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 12e86d4

Please sign in to comment.