@@ -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,27 @@ 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+ //
449+ // IMAGE ID ...
450+ // anImage 171e65262c80 ...
451+ // firstName
452+ // lastNameIsALongOne
453+ // eade5be814e8 ...
454+ // anotherLongName
455+ // bb747ca923a5 ...
456+ if ! lastName || multiLine {
457+ _ , _ = fmt .Fprintln (out )
458+ }
459+ if multiLine && lastName {
460+ _ , _ = fmt .Fprint (out , strings .Repeat (" " , headers [0 ].Width ))
446461 }
447462 }
448463}
@@ -462,6 +477,7 @@ type imgColumn struct {
462477
463478 DetailsValue func (* imageDetails ) string
464479 Color * aec.ANSI
480+ NoEllipsis bool
465481}
466482
467483func (h imgColumn ) Print (clr aec.ANSI , s string ) string {
@@ -478,12 +494,16 @@ func (h imgColumn) Print(clr aec.ANSI, s string) string {
478494func (h imgColumn ) PrintC (clr aec.ANSI , s string ) string {
479495 ln := tui .Width (s )
480496
481- if ln > h .Width {
482- return clr .Apply (tui .Ellipsis (s , h .Width ))
483- }
484-
485497 fill := h .Width - ln
486498
499+ if fill < 0 {
500+ if h .NoEllipsis {
501+ fill = 0
502+ } else {
503+ return clr .Apply (tui .Ellipsis (s , h .Width ))
504+ }
505+ }
506+
487507 l := fill / 2
488508 r := fill - l
489509
@@ -492,20 +512,33 @@ func (h imgColumn) PrintC(clr aec.ANSI, s string) string {
492512
493513func (h imgColumn ) PrintL (clr aec.ANSI , s string ) string {
494514 ln := tui .Width (s )
495- if ln > h .Width {
496- return clr .Apply (tui .Ellipsis (s , h .Width ))
515+
516+ fill := h .Width - ln
517+
518+ if fill < 0 {
519+ if h .NoEllipsis {
520+ fill = 0
521+ } else {
522+ return clr .Apply (tui .Ellipsis (s , h .Width ))
523+ }
497524 }
498525
499- return clr .Apply (s ) + strings .Repeat (" " , h . Width - ln )
526+ return clr .Apply (s ) + strings .Repeat (" " , fill )
500527}
501528
502529func (h imgColumn ) PrintR (clr aec.ANSI , s string ) string {
503530 ln := tui .Width (s )
504- if ln > h .Width {
505- return clr .Apply (tui .Ellipsis (s , h .Width ))
531+ fill := h .Width - ln
532+
533+ if fill < 0 {
534+ if h .NoEllipsis {
535+ fill = 0
536+ } else {
537+ return clr .Apply (tui .Ellipsis (s , h .Width ))
538+ }
506539 }
507540
508- return strings .Repeat (" " , h . Width - ln ) + clr .Apply (s )
541+ return strings .Repeat (" " , fill ) + clr .Apply (s )
509542}
510543
511544// widestFirstColumnValue calculates the width needed to fully display the image names and platforms.
0 commit comments