mirror of https://github.com/chzyer/readline.git
#15: fix prefix completer
This commit is contained in:
parent
5ee706df9b
commit
9364259fb1
|
@ -12,9 +12,7 @@ func NewPrefixCompleter(pc ...*PrefixCompleter) *PrefixCompleter {
|
|||
}
|
||||
|
||||
func PcItem(name string, pc ...*PrefixCompleter) *PrefixCompleter {
|
||||
if len(pc) != 0 {
|
||||
name += " "
|
||||
}
|
||||
return &PrefixCompleter{
|
||||
Name: []rune(name),
|
||||
Children: pc,
|
||||
|
@ -28,7 +26,11 @@ func (p *PrefixCompleter) Do(line []rune, pos int) (newLine [][]rune, offset int
|
|||
for _, child := range p.Children {
|
||||
if len(line) >= len(child.Name) {
|
||||
if runes.HasPrefix(line, child.Name) {
|
||||
if len(line) == len(child.Name) {
|
||||
newLine = append(newLine, []rune{' '})
|
||||
} else {
|
||||
newLine = append(newLine, child.Name)
|
||||
}
|
||||
offset = len(child.Name)
|
||||
lineCompleter = child
|
||||
goNext = true
|
||||
|
|
|
@ -33,8 +33,12 @@ var completer = readline.NewPrefixCompleter(
|
|||
readline.PcItem("bye"),
|
||||
readline.PcItem("help"),
|
||||
readline.PcItem("go",
|
||||
readline.PcItem("build"),
|
||||
readline.PcItem("install"),
|
||||
readline.PcItem("build", readline.PcItem("-o"), readline.PcItem("-v")),
|
||||
readline.PcItem("install",
|
||||
readline.PcItem("-v"),
|
||||
readline.PcItem("-vv"),
|
||||
readline.PcItem("-vvv"),
|
||||
),
|
||||
readline.PcItem("test"),
|
||||
),
|
||||
readline.PcItem("sleep"),
|
||||
|
|
Loading…
Reference in New Issue