-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
raw_item.go
50 lines (40 loc) · 1.39 KB
/
raw_item.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package complete
import (
"src.elv.sh/pkg/cli/modes"
"src.elv.sh/pkg/parse"
"src.elv.sh/pkg/ui"
)
// PlainItem is a simple implementation of RawItem.
type PlainItem string
func (p PlainItem) String() string { return string(p) }
func (p PlainItem) Cook(q parse.PrimaryType) modes.CompletionItem {
s := string(p)
quoted, _ := parse.QuoteAs(s, q)
return modes.CompletionItem{ToInsert: quoted, ToShow: ui.T(s)}
}
// noQuoteItem is a RawItem implementation that does not quote when cooked. This
// type is not exposed, since argument generators never need this.
type noQuoteItem string
func (nq noQuoteItem) String() string { return string(nq) }
func (nq noQuoteItem) Cook(parse.PrimaryType) modes.CompletionItem {
s := string(nq)
return modes.CompletionItem{ToInsert: s, ToShow: ui.T(s)}
}
// ComplexItem is an implementation of RawItem that offers customization options.
type ComplexItem struct {
Stem string // Used in the code and the menu.
CodeSuffix string // Appended to the code.
Display ui.Text // How the item is displayed. If empty, defaults to ui.T(Stem).
}
func (c ComplexItem) String() string { return c.Stem }
func (c ComplexItem) Cook(q parse.PrimaryType) modes.CompletionItem {
quoted, _ := parse.QuoteAs(c.Stem, q)
display := c.Display
if display == nil {
display = ui.T(c.Stem)
}
return modes.CompletionItem{
ToInsert: quoted + c.CodeSuffix,
ToShow: display,
}
}