Skip to content

Commit

Permalink
Final fixes to display
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlandon committed Aug 15, 2023
1 parent 5d04c38 commit ac22261
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/completion/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,11 @@ func (g *group) trimDisplay(comp Candidate, pad, col int) (candidate, padded str
maxDisplayWidth = g.termWidth
}

val = sanitizer.Replace(val)

if comp.displayLen > maxDisplayWidth {
val = color.Trim(val, maxDisplayWidth-4)
val = color.Trim(val, maxDisplayWidth-trailingValueLen)
val += "..." // 3 dots + 1 safety space = -3
val = sanitizer.Replace(val)

return val, " "
}
Expand All @@ -389,22 +390,21 @@ func (g *group) trimDesc(val Candidate, pad int) (desc, padded string) {
pad = g.maxDescAllowed - val.descLen
}

desc = sanitizer.Replace(desc)

// Trim the description accounting for escapes.
if val.descLen > g.maxDescAllowed && g.maxDescAllowed > 0 {
desc = color.Trim(desc, g.maxDescAllowed-3)
desc = color.Trim(desc, g.maxDescAllowed-trailingDescLen)
desc += "..." // 3 dots = -3
desc = g.listSep() + sanitizer.Replace(desc)

return desc, ""
return g.listSep() + desc, ""
}

if val.descLen+pad > g.maxDescAllowed {
pad = g.maxDescAllowed - val.descLen
}

desc = g.listSep() + sanitizer.Replace(desc)

return desc, padSpace(pad)
return g.listSep() + desc, padSpace(pad)
}

func (g *group) getPad(value Candidate, columnIndex int, desc bool) int {
Expand Down
5 changes: 5 additions & 0 deletions internal/completion/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/reeflective/readline/internal/term"
)

const (
trailingDescLen = 3
trailingValueLen = 4
)

var sanitizer = strings.NewReplacer(
"\n", ``,
"\r", ``,
Expand Down

0 comments on commit ac22261

Please sign in to comment.