image/tree: Respect NO_COLOR env variable

Do not use the fancy colored output if NO_COLOR variable is set to 1
following the https://no-color.org/ convention.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-11-13 11:31:05 +01:00
parent 88e324150b
commit be9e6308f5
5 changed files with 46 additions and 15 deletions

View File

@ -292,7 +292,7 @@ func printImageTree(outs command.Streams, view treeView) {
Width: func() int {
maxChipsWidth := 0
for _, chip := range possibleChips {
s := chip.String(isTerm)
s := out.Sprint(chip)
l := tui.Width(s)
maxChipsWidth += l
}
@ -308,9 +308,9 @@ func printImageTree(outs command.Streams, view treeView) {
var b strings.Builder
for _, chip := range possibleChips {
if chip.check(d) {
b.WriteString(chip.String(isTerm))
b.WriteString(out.Sprint(chip))
} else {
b.WriteString(chipPlaceholder.String(isTerm))
b.WriteString(out.Sprint(chipPlaceholder))
}
}
return b.String()