Skip to content

Commit 2ae51e2

Browse files
authored
Merge pull request #6656 from vvoland/img-list-notty-width
image/tree: Don't limit name width if non tty
2 parents c44e8a0 + ed281dd commit 2ae51e2

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Info -> U In Use
21
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Info -> U In Use
21
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Info -> U In Use
21
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Info -> U In Use
21
IMAGE ID DISK USAGE CONTENT SIZE EXTRA

cli/command/image/tree.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ func printImageTree(outs command.Streams, view treeView) {
230230
}
231231

232232
out := tui.NewOutput(outs.Out())
233+
isTerm := out.IsTerminal()
234+
233235
_, width := out.GetTtySize()
234-
if width == 0 {
235-
width = 80
236-
}
237-
if width < 20 {
236+
limitWidth := width == 0
237+
if isTerm && width < 20 {
238238
width = 20
239239
}
240240

@@ -243,9 +243,10 @@ func printImageTree(outs command.Streams, view treeView) {
243243
untaggedColor := out.Color(tui.ColorTertiary)
244244
titleColor := out.Color(tui.ColorTitle)
245245

246-
isTerm := out.IsTerminal()
247-
248-
out.Println(generateLegend(out, width))
246+
// Legend is right-aligned, so don't print it if the width is unlimited
247+
if !limitWidth {
248+
out.Println(generateLegend(out, width))
249+
}
249250

250251
possibleChips := getPossibleChips(view)
251252
columns := []imgColumn{
@@ -340,25 +341,27 @@ func printImageTree(outs command.Streams, view treeView) {
340341
// to display their content.
341342
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
342343
nameWidth := int(width)
343-
for idx, h := range columns {
344-
if h.Width == 0 {
345-
continue
346-
}
347-
d := h.Width
348-
if idx > 0 {
349-
d += columnSpacing
350-
}
351-
// If the first column gets too short, remove remaining columns
352-
if nameWidth-d < 12 {
353-
columns = columns[:idx]
354-
break
344+
if nameWidth > 0 {
345+
for idx, h := range columns {
346+
if h.Width == 0 {
347+
continue
348+
}
349+
d := h.Width
350+
if idx > 0 {
351+
d += columnSpacing
352+
}
353+
// If the first column gets too short, remove remaining columns
354+
if nameWidth-d < 12 {
355+
columns = columns[:idx]
356+
break
357+
}
358+
nameWidth -= d
355359
}
356-
nameWidth -= d
357360
}
358361

359362
// Try to make the first column as narrow as possible
360363
widest := widestFirstColumnValue(columns, images)
361-
if nameWidth > widest {
364+
if width == 0 || nameWidth > widest {
362365
nameWidth = widest
363366
}
364367
columns[0].Width = nameWidth

0 commit comments

Comments
 (0)