MCPcopy Index your code
hub / github.com/docker/cli / Write

Method Write

cli/command/formatter/tabwriter/tabwriter.go:527–596  ·  view source on GitHub ↗

Write writes buf to the writer b. The only errors returned are ones encountered while writing to the underlying output stream.

(buf []byte)

Source from the content-addressed store, hash-verified

525// The only errors returned are ones encountered
526// while writing to the underlying output stream.
527func (b *Writer) Write(buf []byte) (n int, err error) {
528 defer b.handlePanic(&err, "Write")
529
530 // split text into cells
531 n = 0
532 for i, ch := range buf {
533 if b.endChar == 0 {
534 // outside escape
535 switch ch {
536 case '\t', '\v', '\n', '\f':
537 // end of cell
538 b.append(buf[n:i])
539 b.updateWidth()
540 n = i + 1 // ch consumed
541 ncells := b.terminateCell(ch == '\t')
542 if ch == '\n' || ch == '\f' {
543 // terminate line
544 b.addLine(ch == '\f')
545 if ch == '\f' || ncells == 1 {
546 // A '\f' always forces a flush. Otherwise, if the previous
547 // line has only one cell which does not have an impact on
548 // the formatting of the following lines (the last cell per
549 // line is ignored by format()), thus we can flush the
550 // Writer contents.
551 b.flushNoDefers()
552 if ch == '\f' && b.flags&Debug != 0 {
553 // indicate section break
554 b.write0(hbar)
555 }
556 }
557 }
558
559 case Escape:
560 // start of escaped sequence
561 b.append(buf[n:i])
562 b.updateWidth()
563 n = i
564 if b.flags&StripEscape != 0 {
565 n++ // strip Escape
566 }
567 b.startEscape(Escape)
568
569 case '<', '&':
570 // possibly an html tag/entity
571 if b.flags&FilterHTML != 0 {
572 // begin of tag/entity
573 b.append(buf[n:i])
574 b.updateWidth()
575 n = i
576 b.startEscape(ch)
577 }
578 }
579 } else if ch == b.endChar {
580 // inside escape
581 // end of tag/entity
582 j := i + 1
583 if ch == Escape && b.flags&StripEscape != 0 {
584 j = i // strip Escape

Callers 9

prettyPrintVersionFunction · 0.95
postFormatMethod · 0.95
BenchmarkTableFunction · 0.95
BenchmarkPyramidFunction · 0.95
BenchmarkRaggedFunction · 0.95
BenchmarkCodeFunction · 0.95
ExportFunction · 0.95
TestImportTarInvalidFunction · 0.95
write0Method · 0.45

Calls 9

handlePanicMethod · 0.95
appendMethod · 0.95
updateWidthMethod · 0.95
terminateCellMethod · 0.95
addLineMethod · 0.95
flushNoDefersMethod · 0.95
write0Method · 0.95
startEscapeMethod · 0.95
endEscapeMethod · 0.95

Tested by 5

BenchmarkTableFunction · 0.76
BenchmarkPyramidFunction · 0.76
BenchmarkRaggedFunction · 0.76
BenchmarkCodeFunction · 0.76
TestImportTarInvalidFunction · 0.76