-
Notifications
You must be signed in to change notification settings - Fork 1
/
completer.go
31 lines (26 loc) · 901 Bytes
/
completer.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
package main
import (
"github.com/c-bata/go-prompt"
"strings"
)
func completer(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{
{Text: "ls", Description: "Print your todo list"},
{Text: "rm", Description: "Delete from todo list"},
{Text: "set", Description: "Set status of Todo"},
{Text: "new", Description: "Add a new task"},
{Text: "help", Description: "Get detailed description of each command"},
}
currentLine := strings.Split(d.CurrentLineBeforeCursor(), " ")
// get suggestion for set instead
if currentLine[0] == "set" && len(currentLine) == 2 {
s = []prompt.Suggest{
{Text: "start", Description: "Start the task"},
{Text: "done", Description: "Finish task"},
{Text: "restart", Description: "Reset status to New"},
}
} else if len(currentLine) >= 2 {
s = []prompt.Suggest{}
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}