Skip to content

Commit 02e4d05

Browse files
committed
support empty content given to the closestmatch callback
1 parent 23d8605 commit 02e4d05

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

callbacks.go

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func (c *ClosestMatch) CB() Callback {
8383
}
8484
}
8585

86+
// When content is empty, don't show anything but the prompt
87+
if len(content) == 0 {
88+
return ""
89+
}
90+
8691
if inp == "" { // first load or backspaced text
8792
topN = content[:c.MaxShown]
8893
} else if !tab {

examples/closestmatch_empty.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/coxley/rtprompt"
7+
)
8+
9+
func main() {
10+
issues := map[string]string{}
11+
var selected string
12+
cb := rtprompt.ClosestMatch{
13+
Data: issues,
14+
OnSelect: func(s string) { selected = s },
15+
MaxShown: 7,
16+
ShowInstructions: true,
17+
}
18+
prompt := rtprompt.New("Summary: ", cb.CB())
19+
prompt.Wait()
20+
fmt.Printf("Woohoo! You selected: %s\n", selected)
21+
}

0 commit comments

Comments
 (0)