@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/briandowns/spinner"
1313 "github.com/manifoldco/promptui"
14+ promptlist "github.com/manifoldco/promptui/list"
1415 log "github.com/obalunenko/logger"
1516 "github.com/urfave/cli/v2"
1617
@@ -73,19 +74,21 @@ func menu(ctx context.Context) cli.ActionFunc {
7374
7475 years := puzzles .GetYears ()
7576
77+ items := makeMenuItemsList (years , exit )
78+
7679 prompt := promptui.Select {
7780 Label : "Years menu (exit' for exit)" ,
78- Items : append ( years , exit ) ,
81+ Items : items ,
7982 Size : pageSize ,
8083 CursorPos : 0 ,
8184 IsVimMode : false ,
8285 HideHelp : false ,
8386 HideSelected : false ,
8487 Templates : nil ,
8588 Keys : nil ,
86- Searcher : nil ,
89+ Searcher : searcher ( items ) ,
8790 StartInSearchMode : false ,
88- Pointer : nil ,
91+ Pointer : promptui . DefaultCursor ,
8992 Stdin : nil ,
9093 Stdout : nil ,
9194 }
@@ -97,17 +100,19 @@ func menu(ctx context.Context) cli.ActionFunc {
97100func menuPuzzle (ctx context.Context , year string ) error {
98101 solvers := puzzles .DaysByYear (year )
99102
103+ items := makeMenuItemsList (solvers , back , exit )
104+
100105 prompt := promptui.Select {
101106 Label : "Puzzles menu (exit' for exit; back - to return to year selection)" ,
102- Items : append ( solvers , back , exit ) ,
107+ Items : items ,
103108 Size : pageSize ,
104109 CursorPos : 0 ,
105110 IsVimMode : false ,
106111 HideHelp : false ,
107112 HideSelected : false ,
108113 Templates : nil ,
109114 Keys : nil ,
110- Searcher : nil ,
115+ Searcher : searcher ( items ) ,
111116 StartInSearchMode : false ,
112117 Pointer : promptui .DefaultCursor ,
113118 Stdin : nil ,
@@ -117,6 +122,28 @@ func menuPuzzle(ctx context.Context, year string) error {
117122 return handlePuzzleChoices (ctx , year , prompt )
118123}
119124
125+ func makeMenuItemsList (list []string , commands ... string ) []string {
126+ items := make ([]string , 0 , len (list )+ len (commands ))
127+
128+ items = append (items , list ... )
129+
130+ items = append (items , commands ... )
131+
132+ return items
133+ }
134+
135+ func searcher (items []string ) promptlist.Searcher {
136+ return func (input string , index int ) bool {
137+ itm := items [index ]
138+
139+ itm = strings .ReplaceAll (strings .ToLower (itm ), " " , "" )
140+
141+ input = strings .ReplaceAll (strings .ToLower (input ), " " , "" )
142+
143+ return strings .Contains (itm , input )
144+ }
145+ }
146+
120147func handleYearChoices (ctx context.Context , opt promptui.Select ) error {
121148 for {
122149 _ , choice , err := opt .Run ()
0 commit comments