Documentation
¶
Overview ¶
Package indent indents lines of text with a prefix. The New function is used to return a writer that indents the lines written to it. For example:
var buf bytes.Buffer w := indent.New(&buf, "> ") w.Write([]byte(`line 1 line 2 line 3 `)
will result in
> line 1 > line 2 > line 3
Indenters may be nested:
var buf bytes.Buffer w := indent.New(&buf, "> ") w.Write([]byte("line 1\n")) nw := indent.New(w, "..") nw.Write([]byte("line 2\n")) w.Write([]byte("line 3\n"))
will result in
> line 1 > ..line 2 > line 3
The String and Bytes functions are optimized equivalents of
var buf bytes.Buffer() indent.New(&buf, prefix).Write(input) return buf.String() // or buf.Bytes()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NewWriter = New
NewWriter is the name used in github.com/openconfig/goyang/pkg/indent.
Functions ¶
func New ¶
New returns a writer that will prefix all lines written to it with prefix and then writes the results to w. New is intelligent about recursive calls to New. New return w if prefix is the empty string. When nesting, New does not assume it is at the start of a line, it maintains this information as you nest and unwind indenters. It normally is best to only transition between nested writers after a newline has been written.
func Unwrap ¶ added in v1.1.0
Unwrap unwraps and indenter and returns the underlying io.Writer. It will unwrap up to n times or until an io.Writer that is not an indenter is unwrapped. If n is 0 then w is returned. if n is less than zero then all indenters are unwrapped. You should only unwrap after a newline has been written. Anything written to the unwrapped io.Writer should also end with a newline.
Types ¶
This section is empty.