Documentation
¶
Overview ¶
pretty is an extensible utility library to pretty-print nested structures.
Index ¶
Constants ¶
const ( DefaultColumns int = 100 DefaultIndent string = " " )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
type Formatter interface { fmt.Stringer // Set the number of columns to print out. // This method does not mutate. Columns(int) Formatter // contains filtered or unexported methods }
A formatter understands how to turn itself into a string while respecting a desired column target.
func FromStringer ¶
Create a new Formatter from a fmt.Stringer.
type List ¶
type List struct { Elements []Formatter Separator string AdjoinSeparator bool // contains filtered or unexported fields }
An ordered set of items displayed with a separator between them.
Items can be displayed on a single line if it fits within the column constraint. Otherwise items will be displayed across multiple lines.
type Object ¶
Object is a Formatter that prints string-Formatter pairs, respecting columns where possible.
It does this by deciding if the object should be compressed into a single line, or have one field per line.
type Wrap ¶
type Wrap struct {
Prefix, Postfix string
// Require that the Postfix is always on the same line as Value.
PostfixSameline bool
Value Formatter
// contains filtered or unexported fields
}
A Formatter that wraps an inner value with prefixes and postfixes.
Wrap attempts to respect its column target by changing if the prefix and postfix are on the same line as the inner value, or their own lines.
As an example, consider the following instance of Wrap:
Wrap { Prefix: "number(", Postfix: ")" Value: FromString("123456") }
It could be rendered as
number(123456)
or
number( 123456 )
depending on the column constrains.