From 203ce87a3bf168614c0ae4f929be7f53bcb5d226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 24 Jan 2025 16:40:02 +0100 Subject: [PATCH] image/tree: Hide `Content size` column without containerd store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With graph drivers, all content sizes are zero because the compressed content isn't stored. This makes the whole column useless and wasting the terminal space. Hide the whole column if all its values would be zero. Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index a095173bd7d3..9337955a8876 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -226,6 +226,21 @@ func printImageTree(dockerCLI command.Cli, view treeView) error { DetailsValue: func(d *imageDetails) string { return d.ContentSize }, + // Hide if all content sizes are 0 + Hide: func() bool { + zero := units.HumanSize(0.0) + for _, img := range view.images { + if img.Details.ContentSize != zero { + return false + } + for _, sub := range img.Children { + if sub.Details.ContentSize != zero { + return false + } + } + } + return true + }, }, { Title: "Extra", @@ -289,7 +304,15 @@ func printImageTree(dockerCLI command.Cli, view treeView) error { // adjustColumns adjusts the width of the first column to maximize the space // available for image names and removes any columns that would be too narrow // to display their content. +// Also removes any columns that should not be displayed. func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn { + for idx := len(columns) - 1; idx >= 0; idx-- { + h := columns[idx] + if h.Hide != nil && h.Hide() { + columns = append(columns[:idx], columns[idx+1:]...) + } + } + nameWidth := int(width) for idx, h := range columns { if h.Width == 0 { @@ -410,6 +433,7 @@ type imgColumn struct { DetailsValue func(*imageDetails) string Color *aec.ANSI + Hide func() bool } func (h imgColumn) Print(clr aec.ANSI, s string) string {