Skip to content

Commit 8112324

Browse files
committed
Align completion descriptions
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
1 parent ae1f23f commit 8112324

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/tui/components/completion/completion.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ func (c *manager) View() string {
179179
visibleStart := c.scrollOffset
180180
visibleEnd := min(c.scrollOffset+maxItems, len(c.filteredItems))
181181

182+
maxLabelLen := 0
183+
for i := visibleStart; i < visibleEnd; i++ {
184+
labelLen := len(c.filteredItems[i].Label)
185+
if labelLen > maxLabelLen {
186+
maxLabelLen = labelLen
187+
}
188+
}
189+
182190
for i := visibleStart; i < visibleEnd; i++ {
183191
item := c.filteredItems[i]
184192
isSelected := i == c.selected
@@ -190,7 +198,9 @@ func (c *manager) View() string {
190198
itemStyle = styles.CompletionNormalStyle
191199
}
192200

193-
text := item.Label
201+
// Pad label to maxLabelLen so descriptions align
202+
paddedLabel := item.Label + strings.Repeat(" ", maxLabelLen+1-len(item.Label))
203+
text := paddedLabel
194204
if item.Description != "" {
195205
text += " " + styles.CompletionDescStyle.Render(item.Description)
196206
}

0 commit comments

Comments
 (0)