Merge pull request #5757 from vvoland/images-tree-name
image/tree: Print longest names first and use full width
This commit is contained in:
commit
66a584a66d
@ -281,11 +281,23 @@ func printNames(out *streams.Out, headers []imgColumn, img topImage, color, unta
|
|||||||
_, _ = fmt.Fprint(out, headers[0].Print(untaggedColor, "<untagged>"))
|
_, _ = fmt.Fprint(out, headers[0].Print(untaggedColor, "<untagged>"))
|
||||||
}
|
}
|
||||||
|
|
||||||
for nameIdx, name := range img.Names {
|
// TODO: Replace with namesLongestToShortest := slices.SortedFunc(slices.Values(img.Names))
|
||||||
if nameIdx != 0 {
|
// once we move to Go 1.23.
|
||||||
_, _ = fmt.Fprintln(out, "")
|
namesLongestToShortest := make([]string, len(img.Names))
|
||||||
|
copy(namesLongestToShortest, img.Names)
|
||||||
|
sort.Slice(namesLongestToShortest, func(i, j int) bool {
|
||||||
|
return len(namesLongestToShortest[i]) > len(namesLongestToShortest[j])
|
||||||
|
})
|
||||||
|
|
||||||
|
for nameIdx, name := range namesLongestToShortest {
|
||||||
|
// Don't limit first names to the column width because only the last
|
||||||
|
// name will be printed alongside other columns.
|
||||||
|
if nameIdx < len(img.Names)-1 {
|
||||||
|
_, fullWidth := out.GetTtySize()
|
||||||
|
_, _ = fmt.Fprintln(out, color.Apply(truncateRunes(name, int(fullWidth))))
|
||||||
|
} else {
|
||||||
|
_, _ = fmt.Fprint(out, headers[0].Print(color, name))
|
||||||
}
|
}
|
||||||
_, _ = fmt.Fprint(out, headers[0].Print(color, name))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user