MCPcopy Create free account
hub / github.com/docker/cli / format

Method format

cli/command/formatter/tabwriter/tabwriter.go:355–411  ·  view source on GitHub ↗

Format the text between line0 and line1 (excluding line1); pos is the buffer position corresponding to the beginning of line0. Returns the buffer position corresponding to the beginning of line1 and an error, if any.

(pos0 int, line0, line1 int)

Source from the content-addressed store, hash-verified

353// Returns the buffer position corresponding to the beginning of
354// line1 and an error, if any.
355func (b *Writer) format(pos0 int, line0, line1 int) (pos int) {
356 pos = pos0
357 column := len(b.widths)
358 for this := line0; this < line1; this++ {
359 line := b.lines[this]
360
361 if column >= len(line)-1 {
362 continue
363 }
364 // cell exists in this column => this line
365 // has more cells than the previous line
366 // (the last cell per line is ignored because cells are
367 // tab-terminated; the last cell per line describes the
368 // text before the newline/formfeed and does not belong
369 // to a column)
370
371 // print unprinted lines until beginning of block
372 pos = b.writeLines(pos, line0, this)
373 line0 = this
374
375 // column block begin
376 width := b.minwidth // minimal column width
377 discardable := true // true if all cells in this column are empty and "soft"
378 for ; this < line1; this++ {
379 line = b.lines[this]
380 if column >= len(line)-1 {
381 break
382 }
383 // cell exists in this column
384 c := line[column]
385 // update width
386 if w := c.width + b.padding; w > width {
387 width = w
388 }
389 // update discardable
390 if c.width > 0 || c.htab {
391 discardable = false
392 }
393 }
394 // column block end
395
396 // discard empty columns if necessary
397 if discardable && b.flags&DiscardEmptyColumns != 0 {
398 width = 0
399 }
400
401 // format and print all columns to the right of this column
402 // (we know the widths of this column and all columns to the left)
403 b.widths = append(b.widths, width) // push width
404 pos = b.format(pos, line0, this)
405 b.widths = b.widths[0 : len(b.widths)-1] // pop width
406 line0 = this
407 }
408
409 // print unprinted lines until end
410 return b.writeLines(pos, line0, line1)
411}
412

Callers 1

flushNoDefersMethod · 0.95

Calls 1

writeLinesMethod · 0.95

Tested by

no test coverage detected