Skip to content

Commit 13d03b2

Browse files
committed
Give the multiple selection hint
1 parent fd255b1 commit 13d03b2

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

keycodes.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ var (
2626
// KeyForward is the default key to page down during selection.
2727
KeyForward rune = readline.CharForward
2828
KeyForwardDisplay = "→"
29+
30+
// KeySpace is the default key to chose options for checkbox
31+
KeySpace rune = 32
32+
KeySpaceDisplay = "SPACE"
2933
)

keycodes_other.go

-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ import "github.com/chzyer/readline"
88
var (
99
// KeyBackspace is the default key for deleting input text.
1010
KeyBackspace rune = readline.CharBackspace
11-
12-
// KeySpace is the default key to chose options for checkbox
13-
KeySpace rune = 32
1411
)

select.go

+25-16
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ type SelectKeys struct {
109109

110110
// Search is the key used to trigger the search mode for the list. Default to the "/" key.
111111
Search Key
112+
113+
// Select is the key used to trigger the multiple select mode for the list. Default to the space key.
114+
Select Key
112115
}
113116

114117
// Key defines a keyboard code and a display representation for the help menu.
@@ -314,7 +317,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
314317
header := SearchPrompt + cur.Format()
315318
sb.WriteString(header)
316319
} else if !s.HideHelp {
317-
help := s.renderHelp(canSearch)
320+
help := s.renderHelp(canSearch, s.Checkbox)
318321
sb.Write(help)
319322
}
320323

@@ -512,8 +515,9 @@ func (s *Select) prepareTemplates() error {
512515

513516
if tpls.Help == "" {
514517
tpls.Help = fmt.Sprintf(`{{ "Use the arrow keys to navigate:" | faint }} {{ .NextKey | faint }} ` +
515-
`{{ .PrevKey | faint }} {{ .PageDownKey | faint }} {{ .PageUpKey | faint }} ` +
516-
`{{ if .Search }} {{ "and" | faint }} {{ .SearchKey | faint }} {{ "toggles search" | faint }}{{ end }}`)
518+
`{{ .PrevKey | faint }} {{ .PageDownKey | faint }} {{ .PageUpKey | faint }}` +
519+
`{{ if .Search }} {{ " and" | faint }} {{ .SearchKey | faint }} {{ "toggles search" | faint }}{{ end }}` +
520+
`{{ if .MultipleSelect }} {{ " and" | faint }} {{ .SelectKey | faint }} {{ "toggles select" | faint }}{{ end }}`)
517521
}
518522

519523
tpl, err = template.New("").Funcs(tpls.FuncMap).Parse(tpls.Help)
@@ -619,6 +623,7 @@ func (s *Select) setKeys() {
619623
PageUp: Key{Code: KeyBackward, Display: KeyBackwardDisplay},
620624
PageDown: Key{Code: KeyForward, Display: KeyForwardDisplay},
621625
Search: Key{Code: '/', Display: "/"},
626+
Select: Key{Code: KeySpace, Display: KeySpaceDisplay},
622627
}
623628
}
624629

@@ -643,21 +648,25 @@ func (s *Select) renderDetails(item interface{}) [][]byte {
643648
return bytes.Split(output, []byte("\n"))
644649
}
645650

646-
func (s *Select) renderHelp(b bool) []byte {
651+
func (s *Select) renderHelp(b bool, c bool) []byte {
647652
keys := struct {
648-
NextKey string
649-
PrevKey string
650-
PageDownKey string
651-
PageUpKey string
652-
Search bool
653-
SearchKey string
653+
NextKey string
654+
PrevKey string
655+
PageDownKey string
656+
PageUpKey string
657+
Search bool
658+
SearchKey string
659+
MultipleSelect bool
660+
SelectKey string
654661
}{
655-
NextKey: s.Keys.Next.Display,
656-
PrevKey: s.Keys.Prev.Display,
657-
PageDownKey: s.Keys.PageDown.Display,
658-
PageUpKey: s.Keys.PageUp.Display,
659-
SearchKey: s.Keys.Search.Display,
660-
Search: b,
662+
NextKey: s.Keys.Next.Display,
663+
PrevKey: s.Keys.Prev.Display,
664+
PageDownKey: s.Keys.PageDown.Display,
665+
PageUpKey: s.Keys.PageUp.Display,
666+
SearchKey: s.Keys.Search.Display,
667+
SelectKey: s.Keys.Select.Display,
668+
Search: b,
669+
MultipleSelect: c,
661670
}
662671

663672
return render(s.Templates.help, keys)

0 commit comments

Comments
 (0)