Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CatchPrinterError ¶
func CatchPrinterError(err *error)
CatchPrinterError can be used to capture panics caused by a Printer because of an error encountered while attempting to send output. See the Printer interface documentation for details.
Types ¶
type Colorizer ¶
func (*Colorizer) PrintSuccintScalar ¶
type DefaultPrinter ¶
type DefaultPrinter struct {
io.Writer
Flusher
IndentSize int
// contains filtered or unexported fields
}
DefaultPrinter implements a Printer which uses an io.Writer to send output, using IndentSize spaces for each indent level. If IndentSize is negative, then NewLine() does nothing so all the output is on one single line. If IndentSize is 0, then there is no indentation but there are still new lines. If Flusher is not nil, then the printer will call Flush() at the end of each line (good when writing to terminal).
func (*DefaultPrinter) Dedent ¶
func (p *DefaultPrinter) Dedent()
Dedent has the effect of decrementing the indentation level and calls NewLine()
func (*DefaultPrinter) Indent ¶
func (p *DefaultPrinter) Indent()
Indent has the effect of incrementing the indentation level and calls NewLine()
func (*DefaultPrinter) NewLine ¶
func (p *DefaultPrinter) NewLine()
NewLines outputs '\n' followed by a number of spaces corresponding to the current indentation level.
func (*DefaultPrinter) PrintBytes ¶
func (p *DefaultPrinter) PrintBytes(b []byte)
PrintBytes sends the gives bytes verbatim to the printer's writer.
func (*DefaultPrinter) Reset ¶
func (p *DefaultPrinter) Reset()
Reset outputs '\n' unconditionally and resets the indent level.
type Printer ¶
type Printer interface {
Indent()
Dedent()
NewLine()
Reset()
PrintBytes([]byte)
}
The Printer interface can be used to output some structured data.
Indent() starts a new line at an increased indentation level Dedent() starts a new line at a decreased indentation level NewLine() start a new line at the current indentation level Reset() resets the indentation level to 0 and moves to a new line (this cannot be overriden) PrintBytes() outputs bytes at the current position
The methods do not return an error because for this program it's assumed to be an exceptional case that outputting results in an error and the only sensible outcome is to stop the program. Instead, implementations are expected to panic with a *PrinterError when they encounter and error. A user of the Printer interface can use
func printingFunction(p Printer) (err error) {
defer CatchPrinterError(&err)
return doSomePrinting(printer)
}
to capture such errors.
type PrinterError ¶
type PrinterError struct {
Err error
}
A PrinterError contains an error that occurred while a Printer implementation was sending some output.
func (*PrinterError) Error ¶
func (e *PrinterError) Error() string
func (*PrinterError) Unwrap ¶
func (e *PrinterError) Unwrap() error