Skip to content

Commit 2c065e2

Browse files
committed
image/tree: Don't limit name width if non tty
This allows to grep through the output. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent c44e8a0 commit 2c065e2

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

cli/command/image/tree.go

Lines changed: 21 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,8 +243,6 @@ 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-
248246
out.Println(generateLegend(out, width))
249247

250248
possibleChips := getPossibleChips(view)
@@ -290,7 +288,7 @@ func printImageTree(outs command.Streams, view treeView) {
290288
}
291289

292290
le := len("Extra")
293-
if le > maxChipsWidth {
291+
if limitWidth && le > maxChipsWidth {
294292
return le
295293
}
296294
return maxChipsWidth
@@ -340,25 +338,27 @@ func printImageTree(outs command.Streams, view treeView) {
340338
// to display their content.
341339
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
342340
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
341+
if nameWidth > 0 {
342+
for idx, h := range columns {
343+
if h.Width == 0 {
344+
continue
345+
}
346+
d := h.Width
347+
if idx > 0 {
348+
d += columnSpacing
349+
}
350+
// If the first column gets too short, remove remaining columns
351+
if nameWidth-d < 12 {
352+
columns = columns[:idx]
353+
break
354+
}
355+
nameWidth -= d
355356
}
356-
nameWidth -= d
357357
}
358358

359359
// Try to make the first column as narrow as possible
360360
widest := widestFirstColumnValue(columns, images)
361-
if nameWidth > widest {
361+
if width == 0 || nameWidth > widest {
362362
nameWidth = widest
363363
}
364364
columns[0].Width = nameWidth

0 commit comments

Comments
 (0)