From a84846dc69f1fbe032f4534f92e937684b9a3710 Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Sat, 20 Apr 2019 01:15:13 -0700 Subject: [PATCH] improved help message in multiselect (#187) --- examples/longmulti.go | 4 ++-- multiselect.go | 2 +- multiselect_test.go | 24 ++++++++++++------------ select.go | 2 +- select_test.go | 6 +++--- survey_test.go | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/longmulti.go b/examples/longmulti.go index da639525..1a161595 100644 --- a/examples/longmulti.go +++ b/examples/longmulti.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "gopkg.in/AlecAivazis/survey.v1" + survey "gopkg.in/AlecAivazis/survey.v1" ) // the questions to ask @@ -12,7 +12,7 @@ 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", diff --git a/multiselect.go b/multiselect.go index 8aad89a2..a7f04e6a 100644 --- a/multiselect.go +++ b/multiselect.go @@ -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}} diff --git a/multiselect_test.go b/multiselect_test.go index 8617890b..6d73271c 100644 --- a/multiselect_test.go +++ b/multiselect_test.go @@ -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), @@ -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), @@ -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), @@ -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(" ") @@ -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() }, @@ -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)) @@ -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 @@ -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(" ") @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/select.go b/select.go index be7f2401..d9df4053 100644 --- a/select.go +++ b/select.go @@ -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}} diff --git a/select_test.go b/select_test.go index 13a068ef..87ba969e 100644 --- a/select_test.go +++ b/select_test.go @@ -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), @@ -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), @@ -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), diff --git a/survey_test.go b/survey_test.go index 584ab3b1..936807a4 100644 --- a/survey_test.go +++ b/survey_test.go @@ -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(" ") @@ -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() },