2022-03-07 14:57:42 +00:00
|
|
|
package interactive
|
|
|
|
|
|
|
|
import cli "git.tcp.direct/Mirrors/go-prompt"
|
|
|
|
|
|
|
|
func completer(in cli.Document) []cli.Suggest {
|
|
|
|
c := in.CurrentLine()
|
|
|
|
if c == "" {
|
|
|
|
return []cli.Suggest{}
|
|
|
|
}
|
|
|
|
var set []cli.Suggest
|
|
|
|
for command, arguments := range suggestions {
|
2022-07-08 10:41:00 +00:00
|
|
|
head := in.CursorPositionCol()
|
|
|
|
if head > len(command.Text) {
|
2022-03-07 14:57:42 +00:00
|
|
|
head = len(command.Text)
|
|
|
|
}
|
2022-07-08 10:41:00 +00:00
|
|
|
tmpl := &cli.Document{Text: command.Text}
|
2022-03-07 14:57:42 +00:00
|
|
|
one := tmpl.GetWordAfterCursor()
|
2022-07-29 10:44:08 +00:00
|
|
|
if one != "" && one != "use" {
|
|
|
|
set = append(set, cli.Suggest{Text: tmpl.Text})
|
|
|
|
}
|
|
|
|
if one == "use" && len(arguments) > 1 {
|
2022-03-07 14:57:42 +00:00
|
|
|
set = append(set, cli.Suggest{Text: tmpl.Text})
|
|
|
|
}
|
|
|
|
for _, a := range arguments {
|
2022-07-08 10:41:00 +00:00
|
|
|
if head > len(tmpl.Text+a.Text)+1 {
|
2022-03-07 14:57:42 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-07-08 10:41:00 +00:00
|
|
|
tmpl = &cli.Document{Text: tmpl.Text + " " + a.Text}
|
2022-03-07 14:57:42 +00:00
|
|
|
two := tmpl.GetWordAfterCursorWithSpace()
|
|
|
|
if two != "" {
|
|
|
|
set = append(set, cli.Suggest{Text: tmpl.Text})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cli.FilterHasPrefix(set, c, true)
|
|
|
|
}
|