Skip to content

Commit

Permalink
Merge pull request #53 from reeflective/dev
Browse files Browse the repository at this point in the history
Fix completion non-described
  • Loading branch information
maxlandon authored Aug 27, 2023
2 parents 7ee8394 + 50e6237 commit 0a9d478
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions internal/completion/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"strconv"
"strings"

"golang.org/x/exp/slices"

"github.com/reeflective/readline/internal/color"
"github.com/reeflective/readline/internal/term"
"golang.org/x/exp/slices"
)

// group is used to structure different types of completions with different
Expand Down Expand Up @@ -324,6 +325,11 @@ func (g *group) longestValueDescribed(vals []Candidate) int {
longestVal = val.displayLen
}

if val.descLen > longestDesc {
longestDesc = val.descLen

}

if val.descLen > longestDesc {
longestDesc = val.descLen
}
Expand All @@ -333,6 +339,10 @@ func (g *group) longestValueDescribed(vals []Candidate) int {
longestDesc += descSeparatorLen
}

if longestDesc > 0 {
longestDesc += descSeparatorLen
}

// Always add one: there is at least one space between each column.
return longestVal + longestDesc + 1
}
Expand Down Expand Up @@ -398,7 +408,7 @@ func (g *group) trimDesc(val Candidate, pad int) (desc, padded string) {

func (g *group) getPad(value Candidate, columnIndex int, desc bool) int {
columns := g.columnsWidth
var valLen = value.displayLen - 1
valLen := value.displayLen - 1

if desc {
columns = g.descriptionsWidth
Expand Down
2 changes: 1 addition & 1 deletion internal/completion/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (e *Engine) generateGroup(comps Values) func(tag string, values RawValues)
// If we have a remaining group of values without descriptions,
// we will print and use them in a separate, anonymous group.
if len(noDescVals) > 0 {
e.newCompletionGroup(comps, "", vals, descriptions)
e.newCompletionGroup(comps, "", noDescVals, descriptions)
}
}
}
Expand Down

0 comments on commit 0a9d478

Please sign in to comment.