From aa5d00a3a44dda91565bdeafcf5190e1302a1c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 13 Nov 2025 11:35:45 +0100 Subject: [PATCH 1/2] image/tree: Don't limit name width if non tty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously when no terminal was attached the width was assumed to be 80. This is too short for most image names which truncated the names when output was redirect (for example to `grep`). This disabled the name truncation if the terminal width can't be determined. Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 4d032922a..3087aa48a 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -230,11 +230,10 @@ func printImageTree(outs command.Streams, view treeView) { } out := tui.NewOutput(outs.Out()) + isTerm := out.IsTerminal() + _, width := out.GetTtySize() - if width == 0 { - width = 80 - } - if width < 20 { + if isTerm && width < 20 { width = 20 } @@ -243,8 +242,6 @@ func printImageTree(outs command.Streams, view treeView) { untaggedColor := out.Color(tui.ColorTertiary) titleColor := out.Color(tui.ColorTitle) - isTerm := out.IsTerminal() - out.Println(generateLegend(out, width)) possibleChips := getPossibleChips(view) @@ -340,25 +337,27 @@ func printImageTree(outs command.Streams, view treeView) { // to display their content. func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn { nameWidth := int(width) - for idx, h := range columns { - if h.Width == 0 { - continue + if nameWidth > 0 { + for idx, h := range columns { + if h.Width == 0 { + continue + } + d := h.Width + if idx > 0 { + d += columnSpacing + } + // If the first column gets too short, remove remaining columns + if nameWidth-d < 12 { + columns = columns[:idx] + break + } + nameWidth -= d } - d := h.Width - if idx > 0 { - d += columnSpacing - } - // If the first column gets too short, remove remaining columns - if nameWidth-d < 12 { - columns = columns[:idx] - break - } - nameWidth -= d } // Try to make the first column as narrow as possible widest := widestFirstColumnValue(columns, images) - if nameWidth > widest { + if width == 0 || nameWidth > widest { nameWidth = widest } columns[0].Width = nameWidth From ed281ddf5264fa08bbe02265f89f9cfe18787ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 13 Nov 2025 12:11:24 +0100 Subject: [PATCH 2/2] image/list: Print legend only if limiting width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- .../image/testdata/list-command-success.filters.golden | 1 - .../image/testdata/list-command-success.format.golden | 1 - .../image/testdata/list-command-success.match-name.golden | 1 - .../image/testdata/list-command-success.simple.golden | 1 - cli/command/image/tree.go | 6 +++++- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/command/image/testdata/list-command-success.filters.golden b/cli/command/image/testdata/list-command-success.filters.golden index 0d9b30599..cca2da199 100644 --- a/cli/command/image/testdata/list-command-success.filters.golden +++ b/cli/command/image/testdata/list-command-success.filters.golden @@ -1,2 +1 @@ - Info -> U In Use IMAGE ID DISK USAGE CONTENT SIZE EXTRA diff --git a/cli/command/image/testdata/list-command-success.format.golden b/cli/command/image/testdata/list-command-success.format.golden index 0d9b30599..cca2da199 100644 --- a/cli/command/image/testdata/list-command-success.format.golden +++ b/cli/command/image/testdata/list-command-success.format.golden @@ -1,2 +1 @@ - Info -> U In Use IMAGE ID DISK USAGE CONTENT SIZE EXTRA diff --git a/cli/command/image/testdata/list-command-success.match-name.golden b/cli/command/image/testdata/list-command-success.match-name.golden index 0d9b30599..cca2da199 100644 --- a/cli/command/image/testdata/list-command-success.match-name.golden +++ b/cli/command/image/testdata/list-command-success.match-name.golden @@ -1,2 +1 @@ - Info -> U In Use IMAGE ID DISK USAGE CONTENT SIZE EXTRA diff --git a/cli/command/image/testdata/list-command-success.simple.golden b/cli/command/image/testdata/list-command-success.simple.golden index 0d9b30599..cca2da199 100644 --- a/cli/command/image/testdata/list-command-success.simple.golden +++ b/cli/command/image/testdata/list-command-success.simple.golden @@ -1,2 +1 @@ - Info -> U In Use IMAGE ID DISK USAGE CONTENT SIZE EXTRA diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 3087aa48a..0c7ede0de 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -233,6 +233,7 @@ func printImageTree(outs command.Streams, view treeView) { isTerm := out.IsTerminal() _, width := out.GetTtySize() + limitWidth := width == 0 if isTerm && width < 20 { width = 20 } @@ -242,7 +243,10 @@ func printImageTree(outs command.Streams, view treeView) { untaggedColor := out.Color(tui.ColorTertiary) titleColor := out.Color(tui.ColorTitle) - out.Println(generateLegend(out, width)) + // Legend is right-aligned, so don't print it if the width is unlimited + if !limitWidth { + out.Println(generateLegend(out, width)) + } possibleChips := getPossibleChips(view) columns := []imgColumn{