diff --git a/cli/completer.go b/cli/completer.go index be1ba215..01d01df7 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -410,7 +410,7 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) return argOptions[i].Value < argOptions[j].Value }) for _, item := range argOptions { - if strings.HasPrefix(item.Value, argInput) { + if strings.HasPrefix(item.Value, argInput) || (len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput)) { filteredOptions = append(filteredOptions, item) } } @@ -421,12 +421,14 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) } for _, item := range filteredOptions { option := item.Value + " " - if len(filteredOptions) > 1 && len(item.Detail) > 0 { + if len(filteredOptions) > 0 && len(item.Detail) > 0 { option += fmt.Sprintf("(%v)", item.Detail) } if strings.HasPrefix(option, argInput) { options = append(options, []rune(option[len(argInput):])) offset = len(argInput) + } else if len(item.Detail) > 0 && strings.HasPrefix(item.Detail, argInput) { + options = append(options, []rune(option)) } } return diff --git a/vendor/github.com/chzyer/readline/complete.go b/vendor/github.com/chzyer/readline/complete.go index 1c15aed5..a5a23011 100644 --- a/vendor/github.com/chzyer/readline/complete.go +++ b/vendor/github.com/chzyer/readline/complete.go @@ -45,19 +45,34 @@ func newOpCompleter(w io.Writer, op *Operation, width int) *opCompleter { width: width, } } + +func (o *opCompleter) truncateBufferAfterLastEqual(completion []rune) { + bufRunes := o.op.buf.Runes() + for i := len(bufRunes) - 1; i >= 0; i-- { + if bufRunes[i] == '=' { + prefix := bufRunes[i+1:] // part after '=' in buffer + if len(prefix) > 0 && len(completion) > 0 && string(completion[:len(prefix)]) == string(prefix) { + o.op.buf.Set(bufRunes[:i+1]) // Keep content till '=' + } + break + } + } +} + func (o *opCompleter) writeRunes(candidate []rune) { - detailIndex := len(candidate) + selected := candidate spaceFound := false for idx, r := range candidate { if r == ' ' { spaceFound = true } if spaceFound && r == '(' { - detailIndex = idx + o.truncateBufferAfterLastEqual(candidate[idx+1:]) + selected = candidate[:idx] break } } - o.op.buf.WriteRunes(candidate[:detailIndex]) + o.op.buf.WriteRunes(selected) } func (o *opCompleter) doSelect() { @@ -107,7 +122,7 @@ func (o *opCompleter) OnComplete() bool { // only Aggregate candidates in non-complete mode if !o.IsInCompleteMode() { if len(newLines) == 1 { - buf.WriteRunes(newLines[0]) + o.writeRunes(newLines[0]) o.ExitCompleteMode(false) return true }