Skip to content

Commit 98de6c5

Browse files
committed
image/tree: Allow image names to overflow instead of truncating
Users were experiencing poor UX when image names were truncated in the table output. Instead of cutting off long image names with ellipsis, the names now wrap to the next line to ensure full visibility. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 511dad6 commit 98de6c5

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

cli/command/image/tree.go

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ func printImageTree(outs command.Streams, view treeView) {
258258
possibleChips := getPossibleChips(view)
259259
columns := []imgColumn{
260260
{
261-
Title: "Image",
262-
Align: alignLeft,
263-
Width: 0,
261+
Title: "Image",
262+
Align: alignLeft,
263+
Width: 0,
264+
NoEllipsis: true,
264265
},
265266
{
266267
Title: "ID",
@@ -436,13 +437,19 @@ func printNames(out tui.Output, headers []imgColumn, img topImage, color, untagg
436437
}
437438

438439
for nameIdx, name := range img.Names {
439-
// Don't limit first names to the column width because only the last
440-
// name will be printed alongside other columns.
441-
if nameIdx < len(img.Names)-1 {
442-
_, fullWidth := out.GetTtySize()
443-
_, _ = fmt.Fprintln(out, color.Apply(tui.Ellipsis(name, int(fullWidth))))
444-
} else {
445-
_, _ = fmt.Fprint(out, headers[0].Print(color, name))
440+
nameWidth := tui.Width(name)
441+
lastName := nameIdx == len(img.Names)-1
442+
multiLine := nameWidth > headers[0].Width
443+
444+
_, _ = fmt.Fprint(out, headers[0].Print(color, name))
445+
446+
// Print each name on its own line, including the last,
447+
// unless the last name fits into the column.
448+
if !lastName || multiLine {
449+
_, _ = fmt.Fprintln(out)
450+
}
451+
if multiLine && lastName {
452+
_, _ = fmt.Fprint(out, strings.Repeat(" ", headers[0].Width))
446453
}
447454
}
448455
}
@@ -462,6 +469,7 @@ type imgColumn struct {
462469

463470
DetailsValue func(*imageDetails) string
464471
Color *aec.ANSI
472+
NoEllipsis bool
465473
}
466474

467475
func (h imgColumn) Print(clr aec.ANSI, s string) string {
@@ -478,12 +486,16 @@ func (h imgColumn) Print(clr aec.ANSI, s string) string {
478486
func (h imgColumn) PrintC(clr aec.ANSI, s string) string {
479487
ln := tui.Width(s)
480488

481-
if ln > h.Width {
482-
return clr.Apply(tui.Ellipsis(s, h.Width))
483-
}
484-
485489
fill := h.Width - ln
486490

491+
if fill < 0 {
492+
if h.NoEllipsis {
493+
fill = 0
494+
} else {
495+
return clr.Apply(tui.Ellipsis(s, h.Width))
496+
}
497+
}
498+
487499
l := fill / 2
488500
r := fill - l
489501

@@ -492,20 +504,33 @@ func (h imgColumn) PrintC(clr aec.ANSI, s string) string {
492504

493505
func (h imgColumn) PrintL(clr aec.ANSI, s string) string {
494506
ln := tui.Width(s)
495-
if ln > h.Width {
496-
return clr.Apply(tui.Ellipsis(s, h.Width))
507+
508+
fill := h.Width - ln
509+
510+
if fill < 0 {
511+
if h.NoEllipsis {
512+
fill = 0
513+
} else {
514+
return clr.Apply(tui.Ellipsis(s, h.Width))
515+
}
497516
}
498517

499-
return clr.Apply(s) + strings.Repeat(" ", h.Width-ln)
518+
return clr.Apply(s) + strings.Repeat(" ", fill)
500519
}
501520

502521
func (h imgColumn) PrintR(clr aec.ANSI, s string) string {
503522
ln := tui.Width(s)
504-
if ln > h.Width {
505-
return clr.Apply(tui.Ellipsis(s, h.Width))
523+
fill := h.Width - ln
524+
525+
if fill < 0 {
526+
if h.NoEllipsis {
527+
fill = 0
528+
} else {
529+
return clr.Apply(tui.Ellipsis(s, h.Width))
530+
}
506531
}
507532

508-
return strings.Repeat(" ", h.Width-ln) + clr.Apply(s)
533+
return strings.Repeat(" ", fill) + clr.Apply(s)
509534
}
510535

511536
// widestFirstColumnValue calculates the width needed to fully display the image names and platforms.

0 commit comments

Comments
 (0)