|
9 | 9 |
|
10 | 10 | "github.com/containerd/platforms"
|
11 | 11 | "github.com/docker/cli/cli/command"
|
12 |
| - "github.com/docker/cli/cli/streams" |
13 | 12 | "github.com/docker/docker/api/types/filters"
|
14 | 13 | imagetypes "github.com/docker/docker/api/types/image"
|
15 | 14 | "github.com/docker/docker/pkg/stringid"
|
@@ -230,64 +229,76 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
|
230 | 229 |
|
231 | 230 | // Print images
|
232 | 231 | for _, img := range images {
|
233 |
| - printNames(out, columns, img, topNameColor, untaggedColor) |
234 |
| - printDetails(out, columns, normalColor, img.Details) |
235 |
| - |
236 |
| - if len(img.Children) > 0 || view.imageSpacing { |
237 |
| - _, _ = fmt.Fprintln(out) |
238 |
| - } |
239 |
| - printChildren(out, columns, img, normalColor) |
| 232 | + _, _ = fmt.Fprint(out, formatImageTree(img, columns, view.imageSpacing, normalColor, topNameColor, untaggedColor)) |
240 | 233 | _, _ = fmt.Fprintln(out)
|
241 | 234 | }
|
242 | 235 |
|
243 | 236 | return nil
|
244 | 237 | }
|
245 | 238 |
|
246 |
| -func printDetails(out *streams.Out, headers []imgColumn, defaultColor aec.ANSI, details imageDetails) { |
| 239 | +func formatImageTree(img topImage, columns []imgColumn, imgSpacing bool, normalColor, topNameColor, untaggedColor aec.ANSI) (out string) { |
| 240 | + out += printNames(columns, img, topNameColor, untaggedColor) |
| 241 | + out += printDetails(columns, normalColor, img.Details) |
| 242 | + |
| 243 | + if len(img.Children) > 0 || imgSpacing { |
| 244 | + out += "\n" |
| 245 | + } |
| 246 | + out += printChildren(columns, img, normalColor) |
| 247 | + |
| 248 | + return out |
| 249 | +} |
| 250 | + |
| 251 | +func printDetails(headers []imgColumn, defaultColor aec.ANSI, details imageDetails) (out string) { |
247 | 252 | for _, h := range headers {
|
248 | 253 | if h.DetailsValue == nil {
|
249 | 254 | continue
|
250 | 255 | }
|
251 | 256 |
|
252 |
| - _, _ = fmt.Fprint(out, strings.Repeat(" ", columnSpacing)) |
| 257 | + out += strings.Repeat(" ", columnSpacing) |
253 | 258 | clr := defaultColor
|
254 | 259 | if h.Color != nil {
|
255 | 260 | clr = *h.Color
|
256 | 261 | }
|
257 | 262 | val := h.DetailsValue(&details)
|
258 |
| - _, _ = fmt.Fprint(out, h.Print(clr, val)) |
| 263 | + out += h.Print(clr, val) |
259 | 264 | }
|
| 265 | + |
| 266 | + return out |
260 | 267 | }
|
261 | 268 |
|
262 |
| -func printChildren(out *streams.Out, headers []imgColumn, img topImage, normalColor aec.ANSI) { |
| 269 | +func printChildren(headers []imgColumn, img topImage, normalColor aec.ANSI) (out string) { |
263 | 270 | for idx, sub := range img.Children {
|
264 | 271 | clr := normalColor
|
265 | 272 | if !sub.Available {
|
266 | 273 | clr = normalColor.With(aec.Faint)
|
267 | 274 | }
|
268 | 275 |
|
269 | 276 | if idx != len(img.Children)-1 {
|
270 |
| - _, _ = fmt.Fprint(out, headers[0].Print(clr, "├─ "+sub.Platform)) |
| 277 | + out += headers[0].Print(clr, "├─ "+sub.Platform) |
271 | 278 | } else {
|
272 |
| - _, _ = fmt.Fprint(out, headers[0].Print(clr, "└─ "+sub.Platform)) |
| 279 | + out += headers[0].Print(clr, "└─ "+sub.Platform) |
273 | 280 | }
|
274 | 281 |
|
275 |
| - printDetails(out, headers, clr, sub.Details) |
276 |
| - _, _ = fmt.Fprintln(out, "") |
| 282 | + out += printDetails(headers, clr, sub.Details) |
| 283 | + out += "\n" |
277 | 284 | }
|
| 285 | + |
| 286 | + return out |
278 | 287 | }
|
279 | 288 |
|
280 |
| -func printNames(out *streams.Out, headers []imgColumn, img topImage, color, untaggedColor aec.ANSI) { |
| 289 | +func printNames(headers []imgColumn, img topImage, color, untaggedColor aec.ANSI) (out string) { |
281 | 290 | if len(img.Names) == 0 {
|
282 |
| - _, _ = fmt.Fprint(out, headers[0].Print(untaggedColor, "<untagged>")) |
| 291 | + out += headers[0].Print(untaggedColor, "<untagged>") |
283 | 292 | }
|
284 | 293 |
|
285 | 294 | for nameIdx, name := range img.Names {
|
286 | 295 | if nameIdx != 0 {
|
287 |
| - _, _ = fmt.Fprintln(out, "") |
| 296 | + out += "\n" |
288 | 297 | }
|
289 |
| - _, _ = fmt.Fprint(out, headers[0].Print(color, name)) |
| 298 | + out += headers[0].Print(color, name) |
290 | 299 | }
|
| 300 | + |
| 301 | + return out |
291 | 302 | }
|
292 | 303 |
|
293 | 304 | type alignment int
|
|
0 commit comments