Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
When using select or multiselect, the user is prompted to make a sele…
Browse files Browse the repository at this point in the history
…ction using space, but entering space causes results to be filtered by space. This commit updates the prompt to tell users to make a selection using the enter key. (#269)
  • Loading branch information
patrickdillon authored Feb 10, 2020
1 parent e4af3b3 commit 45c6db3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var MultiSelectQuestionTemplate = `
{{- color "default+hb"}}{{ .Message }}{{ .FilterMessage }}{{color "reset"}}
{{- if .ShowAnswer}}{{color "cyan"}} {{.Answer}}{{color "reset"}}{{"\n"}}
{{- else }}
{{- " "}}{{- color "cyan"}}[Use arrows to move, space to select, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- " "}}{{- color "cyan"}}[Use arrows to move, enter to select, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- "\n"}}
{{- range $ix, $option := .PageEntries}}
{{- if eq $ix $.SelectedIndex}}{{color "cyan"}}{{ SelectFocusIcon }}{{color "reset"}}{{else}} {{end}}
Expand Down
24 changes: 12 additions & 12 deletions multiselect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestMultiSelectRender(t *testing.T) {
},
strings.Join(
[]string{
fmt.Sprintf("%s Pick your words: [Use arrows to move, space to select, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your words: [Use arrows to move, enter to select, type to filter]", core.QuestionIcon),
fmt.Sprintf(" %s foo", core.UnmarkedOptionIcon),
fmt.Sprintf(" %s bar", core.MarkedOptionIcon),
fmt.Sprintf("%s %s baz", core.SelectFocusIcon, core.UnmarkedOptionIcon),
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestMultiSelectRender(t *testing.T) {
},
strings.Join(
[]string{
fmt.Sprintf("%s Pick your words: [Use arrows to move, space to select, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
fmt.Sprintf("%s Pick your words: [Use arrows to move, enter to select, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
fmt.Sprintf(" %s foo", core.UnmarkedOptionIcon),
fmt.Sprintf(" %s bar", core.MarkedOptionIcon),
fmt.Sprintf("%s %s baz", core.SelectFocusIcon, core.UnmarkedOptionIcon),
Expand All @@ -95,7 +95,7 @@ func TestMultiSelectRender(t *testing.T) {
strings.Join(
[]string{
fmt.Sprintf("%s This is helpful", core.HelpIcon),
fmt.Sprintf("%s Pick your words: [Use arrows to move, space to select, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your words: [Use arrows to move, enter to select, type to filter]", core.QuestionIcon),
fmt.Sprintf(" %s foo", core.UnmarkedOptionIcon),
fmt.Sprintf(" %s bar", core.MarkedOptionIcon),
fmt.Sprintf("%s %s baz", core.SelectFocusIcon, core.UnmarkedOptionIcon),
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Select Monday.
c.Send(string(terminal.KeyArrowDown))
c.SendLine(" ")
Expand All @@ -151,7 +151,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Default: []string{"Tuesday", "Thursday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
c.SendLine("")
c.ExpectEOF()
},
Expand All @@ -165,7 +165,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Default: []string{"Tuesday", "Thursday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Deselect Tuesday.
c.Send(string(terminal.KeyArrowDown))
c.Send(string(terminal.KeyArrowDown))
Expand All @@ -182,7 +182,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Help: "Saturday is best",
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter, ? for more help]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter, ? for more help]")
c.Send("?")
c.ExpectString("Saturday is best")
// Select Saturday
Expand All @@ -200,7 +200,7 @@ func TestMultiSelectPrompt(t *testing.T) {
PageSize: 1,
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Select Monday.
c.Send(string(terminal.KeyArrowDown))
c.SendLine(" ")
Expand All @@ -216,7 +216,7 @@ func TestMultiSelectPrompt(t *testing.T) {
VimMode: true,
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Select Tuesday.
c.Send("jj ")
// Select Thursday.
Expand All @@ -235,7 +235,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Filter down to Tuesday.
c.Send("Tues")
// Select Tuesday.
Expand All @@ -252,7 +252,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Filter down to Tuesday.
c.Send("tues")
// Select Tuesday.
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestMultiSelectPrompt(t *testing.T) {
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
},
func(c *expect.Console) {
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Filter down to Tuesday.
c.Send("Tues")
// Select Tuesday.
Expand Down
2 changes: 1 addition & 1 deletion select.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var SelectQuestionTemplate = `
{{- color "default+hb"}}{{ .Message }}{{ .FilterMessage }}{{color "reset"}}
{{- if .ShowAnswer}}{{color "cyan"}} {{.Answer}}{{color "reset"}}{{"\n"}}
{{- else}}
{{- " "}}{{- color "cyan"}}[Use arrows to move, space to select, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- " "}}{{- color "cyan"}}[Use arrows to move, enter to select, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- "\n"}}
{{- range $ix, $choice := .PageEntries}}
{{- if eq $ix $.SelectedIndex}}{{color "cyan+b"}}{{ SelectFocusIcon }} {{else}}{{color "default+hb"}} {{end}}
Expand Down
6 changes: 3 additions & 3 deletions select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestSelectRender(t *testing.T) {
SelectTemplateData{SelectedIndex: 2, PageEntries: prompt.Options},
strings.Join(
[]string{
fmt.Sprintf("%s Pick your word: [Use arrows to move, space to select, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your word: [Use arrows to move, enter to select, type to filter]", core.QuestionIcon),
" foo",
" bar",
fmt.Sprintf("%s baz", core.SelectFocusIcon),
Expand All @@ -63,7 +63,7 @@ func TestSelectRender(t *testing.T) {
SelectTemplateData{SelectedIndex: 2, PageEntries: prompt.Options},
strings.Join(
[]string{
fmt.Sprintf("%s Pick your word: [Use arrows to move, space to select, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
fmt.Sprintf("%s Pick your word: [Use arrows to move, enter to select, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
" foo",
" bar",
fmt.Sprintf("%s baz", core.SelectFocusIcon),
Expand All @@ -79,7 +79,7 @@ func TestSelectRender(t *testing.T) {
strings.Join(
[]string{
fmt.Sprintf("%s This is helpful", core.HelpIcon),
fmt.Sprintf("%s Pick your word: [Use arrows to move, space to select, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your word: [Use arrows to move, enter to select, type to filter]", core.QuestionIcon),
" foo",
" bar",
fmt.Sprintf("%s baz", core.SelectFocusIcon),
Expand Down
4 changes: 2 additions & 2 deletions survey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestAsk(t *testing.T) {
c.SendLine("Johnny Appleseed")

// MultiSelect
c.ExpectString("What days do you prefer: [Use arrows to move, space to select, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, enter to select, type to filter]")
// Select Monday.
c.Send(string(terminal.KeyArrowDown))
c.Send(" ")
Expand All @@ -151,7 +151,7 @@ func TestAsk(t *testing.T) {
c.SendLine("")

// Select
c.ExpectString("Choose a color: [Use arrows to move, space to select, type to filter]")
c.ExpectString("Choose a color: [Use arrows to move, enter to select, type to filter]")
c.SendLine("yellow")
c.ExpectEOF()
},
Expand Down

0 comments on commit 45c6db3

Please sign in to comment.