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

Commit

Permalink
improved help message in multiselect (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Apr 20, 2019
1 parent 5d9df01 commit a84846d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/longmulti.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"
"strings"

"gopkg.in/AlecAivazis/survey.v1"
survey "gopkg.in/AlecAivazis/survey.v1"
)

// the questions to ask
var multiQs = []*survey.Question{
{
Name: "letter",
Prompt: &survey.MultiSelect{
Message: "Choose one or more words :",
Message: "Choose one or more words :",
Options: []string{
"Afghanistan",
"Åland Islands",
Expand Down
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, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- " "}}{{- color "cyan"}}[Use arrows to move, space 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, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your words: [Use arrows to move, space 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, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
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 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, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your words: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter, ? for more help]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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 @@ -49,7 +49,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, type to filter{{- if and .Help (not .ShowHelp)}}, {{ HelpInputRune }} for more help{{end}}]{{color "reset"}}
{{- " "}}{{- color "cyan"}}[Use arrows to move, space 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, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your word: [Use arrows to move, space 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, type to filter, %s for more help]", core.QuestionIcon, string(core.HelpInputRune)),
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)),
" 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, type to filter]", core.QuestionIcon),
fmt.Sprintf("%s Pick your word: [Use arrows to move, space 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, type to filter]")
c.ExpectString("What days do you prefer: [Use arrows to move, space 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, type to filter]")
c.ExpectString("Choose a color: [Use arrows to move, space to select, type to filter]")
c.SendLine("yellow")
c.ExpectEOF()
},
Expand Down

0 comments on commit a84846d

Please sign in to comment.