@@ -22,10 +22,14 @@ type ClosestMatch struct {
22
22
OnSelect func (string )
23
23
MaxShown int
24
24
25
- // default: FgWhite (aka nothing)
26
- MatchColor * color.Color
25
+ // default: "Use <TAB> and <ENTER> to select from below. Otherwise press <ENTER> when ready"
26
+ Instructions string
27
+ ShowInstructions bool
28
+
27
29
// default: FgBlue
28
30
SelectedColor * color.Color
31
+ // default: FgHiBlack
32
+ InstructionColor * color.Color
29
33
}
30
34
31
35
// CB returns a configured callback to use with Prompt
@@ -34,12 +38,15 @@ func (c *ClosestMatch) CB() Callback {
34
38
// later
35
39
delim := "::CBDELIM::"
36
40
37
- if c .MatchColor == nil {
38
- c .MatchColor = color .New (color .FgWhite )
39
- }
40
41
if c .SelectedColor == nil {
41
42
c .SelectedColor = color .New (color .FgBlue )
42
43
}
44
+ if c .InstructionColor == nil {
45
+ c .InstructionColor = color .New (color .FgHiBlack )
46
+ }
47
+ if c .Instructions == "" {
48
+ c .Instructions = "Use <TAB> and <ENTER> to select from below. Otherwise press <ENTER> when ready"
49
+ }
43
50
44
51
var content []string
45
52
for k , v := range c .Data {
@@ -85,26 +92,22 @@ func (c *ClosestMatch) CB() Callback {
85
92
return c .joinLines (
86
93
topN ,
87
94
preproc ,
88
- inp != "" , // rank
89
95
lastSelected ,
90
96
)
91
97
}
92
98
}
93
99
94
- func (c * ClosestMatch ) joinLines (lines []string , preproc func (string ) string , rank bool , selected int ) string {
100
+ func (c * ClosestMatch ) joinLines (lines []string , preproc func (string ) string , selected int ) string {
95
101
var output string
102
+ if c .ShowInstructions {
103
+ output += c .InstructionColor .Sprintln (c .Instructions )
104
+ }
96
105
for i , line := range lines {
97
106
line = preproc (line )
98
- // If the input isn't ranked, text hasn't been typed. No need to
99
- // color / make note
100
- if ! rank {
101
- output += fmt .Sprintf ("%s\n " , line )
102
- continue
103
- }
104
107
105
- // Highlight closest match if nothing has been selected yet
108
+ // Nothing has been selected yet
106
109
if i == 0 && selected == - 1 {
107
- output += c . MatchColor . Sprintf ( "%s \n " , line )
110
+ output += fmt . Sprintln ( line )
108
111
continue
109
112
}
110
113
@@ -115,7 +118,7 @@ func (c *ClosestMatch) joinLines(lines []string, preproc func(string) string, ra
115
118
}
116
119
117
120
// Plain jane text
118
- output += fmt .Sprintf ( "%s \n " , line )
121
+ output += fmt .Sprintln ( line )
119
122
}
120
123
return output
121
124
}
0 commit comments