forked from docker/docker-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
58 lines (46 loc) · 1.29 KB
/
command.go
File metadata and controls
58 lines (46 loc) · 1.29 KB
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
51
52
53
54
55
56
57
58
package completions
import (
"slices"
"strings"
"github.com/docker/docker-agent/pkg/tui/commands"
"github.com/docker/docker-agent/pkg/tui/components/completion"
)
type commandCompletion struct {
categories []commands.Category
}
func NewCommandCompletion(categories []commands.Category) Completion {
return &commandCompletion{
categories: categories,
}
}
func (c *commandCompletion) AutoSubmit() bool {
return true // Commands auto-submit: selecting inserts command text and sends it
}
func (c *commandCompletion) RequiresEmptyEditor() bool {
return true
}
func (c *commandCompletion) Trigger() string {
return "/"
}
func (c *commandCompletion) Items() []completion.Item {
var items []completion.Item
for _, cmd := range c.categories {
for _, command := range cmd.Commands {
items = append(items, completion.Item{
Label: command.Label,
Description: command.Description,
Value: command.SlashCommand,
})
}
}
return sortItemsByLabel(items)
}
func sortItemsByLabel(items []completion.Item) []completion.Item {
slices.SortFunc(items, func(a, b completion.Item) int {
return strings.Compare(strings.ToLower(a.Label), strings.ToLower(b.Label))
})
return items
}
func (c *commandCompletion) MatchMode() completion.MatchMode {
return completion.MatchPrefix
}