-
Notifications
You must be signed in to change notification settings - Fork 2
/
completer.go
90 lines (86 loc) · 3.38 KB
/
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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// This file is part of Fwew.
// Fwew is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Fwew is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Fwew. If not, see http://gnu.org/licenses/
// Package main contains all the things. completer.go contains the ingredients for prompt completion.
package main
import (
"fmt"
"github.com/c-bata/go-prompt"
"strings"
)
func executor(cmd string) {
if cmd != "" {
if strings.HasPrefix(cmd, "/") {
slashCommand(cmd, false)
} else {
if *numConvert {
fmt.Println(Convert(cmd, *reverse))
} else {
printResults(fwew(cmd))
}
}
} else {
fmt.Println()
}
}
func completer(d prompt.Document) []prompt.Suggest {
if d.GetWordBeforeCursor() == "" {
return []prompt.Suggest{}
}
s := []prompt.Suggest{
{Text: "/set", Description: "set option(s)"},
{Text: "/unset", Description: "unset option(s)"},
{Text: "/list", Description: "list entries satisfying given condition(s)"},
{Text: "/random", Description: "list random entries"},
{Text: "/update", Description: "update the dictionary data file"},
{Text: "/commands", Description: "show commands help"},
{Text: "/help", Description: "show usage help"},
{Text: "/exit", Description: "end program"},
{Text: "/quit", Description: "end program"},
{Text: "/q", Description: "end program"},
{Text: "r", Description: Text("usageR")},
{Text: "i", Description: Text("usageI")},
{Text: "ipa", Description: Text("usageIPA")},
{Text: "n", Description: Text("usageN")},
{Text: "a", Description: Text("usageA")},
{Text: "m", Description: Text("usageM")},
{Text: "s", Description: Text("usageS")},
{Text: "l=de", Description: "Deutsch"},
{Text: "l=eng", Description: "English"},
{Text: "l=est", Description: "Eesti"},
{Text: "l=hu", Description: "Magyar"},
{Text: "l=nl", Description: "Nederlands"},
{Text: "l=pl", Description: "Polski"},
{Text: "l=ru", Description: "Русский"},
{Text: "l=sv", Description: "Svenska"},
{Text: "pos", Description: "part of speech"},
{Text: "word", Description: "word"},
{Text: "words", Description: "words"},
{Text: "syllables", Description: "syllables"},
{Text: "random", Description: "random number"},
{Text: "where", Description: "add condition to random"},
{Text: "starts", Description: "field starts with"},
{Text: "ends", Description: "field ends with"},
{Text: "first", Description: "list oldest words"},
{Text: "last", Description: "list newest words"},
{Text: "has", Description: "all matches of condition"},
{Text: "is", Description: "exact matches of condition"},
{Text: ">=", Description: "syllable count greater or equal"},
{Text: ">", Description: "syllable count greater"},
{Text: "<=", Description: "syllable count less or equal"},
{Text: "<", Description: "syllable count less"},
{Text: "=", Description: "syllable count equal"},
{Text: "and", Description: "add condition to narrow search"},
}
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
}