302 unmodified lines
Expand all
span := func(hs []pickerHint) int { return lo.SumBy(hs, pickerHint.width) + 3*(len(hs)-1) }
for len(hs) > 1 && span(hs) > w {
hs = hs[:len(hs)-1]
}
col := max(1, (w-hs[len(hs)-1].width())/max(1, len(hs)-1)) // one hint is pinned right, so col is unused
x := 0
free, gaps := w-lo.SumBy(hs, pickerHint.width), max(1, len(hs)-1)
for i, h := range hs {
next := i * col
if i == len(hs)-1 {
next = w - h.width()
if i > 0 {
b.WriteString(strings.Repeat(" ", free/gaps+lo.Ternary(i <= free%gaps, 1, 0)))
}
b.WriteString(strings.Repeat(" ", max(0, next-x)))
b.WriteString(hint(h.k, h.act))
x = max(next, x) + h.width()
}
return b.String()
}
186 unmodified lines
Expand all