Documentation ¶
Overview ¶
Package pretty contains utilities for formatting terminal help output, and a use of those to display marker help.
Terminal Output ¶
The Span interface and Table struct allow you to construct tables with colored formatting, without causing ANSI formatting characters to mess up width calculations.
Marker Help ¶
The MarkersSummary prints a summary table for marker help, while the MarkersDetails prints out more detailed information, with explainations of the individual marker fields.
Index ¶
- type Decoration
- type Span
- func FieldSyntaxHelp(arg help.FieldHelp) Span
- func FromWriter(run func(io.Writer) error) Span
- func Indented(amt int, content Span) Span
- func Line(content Span) Span
- func MarkerSyntaxHelp(def help.MarkerDoc) Span
- func MarkersDetails(fullDetail bool, groupName string, markers []help.MarkerDoc) Span
- func MarkersSummary(groupName string, markers []help.MarkerDoc) Span
- func Newlines(amt int) Span
- type SpanWriter
- type Table
- type TableCalculator
- type Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoration ¶
Decoration represents a terminal decoration.
func (Decoration) Containing ¶
func (d Decoration) Containing(contents Span) Span
Containing returns a Span that has the given decoration applied.
type Span ¶
type Span interface { // VisualLength reports the "width" as perceived by the user on the terminal // (i.e. widest line, ignoring ANSI escape characters). VisualLength() int // WriteTo writes the full span contents to the given writer. WriteTo(io.Writer) error }
Span is a chunk of content that is writable to an output, but knows how to calculate its apparent visual "width" on the terminal (not to be confused with the raw length, which may include zero-width coloring sequences).
func FieldSyntaxHelp ¶
func FromWriter ¶
FromWriter returns a span that takes content from a function expecting a Writer.
func MarkerSyntaxHelp ¶
MarkerSyntaxHelp assembles syntax help for a given marker.
func MarkersDetails ¶
MarkersDetails returns detailed help for the given markers, including detailed field help.
func MarkersSummary ¶
MarkersSummary returns a condensed summary of help for the given markers.
type SpanWriter ¶
type SpanWriter struct {
// contains filtered or unexported fields
}
SpanWriter is a span that contains multiple sub-spans.
func (*SpanWriter) Print ¶
func (m *SpanWriter) Print(s Span)
Print adds a new span to this SpanWriter.
func (*SpanWriter) VisualLength ¶
func (m *SpanWriter) VisualLength() int
type Table ¶
type Table struct { Sizing *TableCalculator // contains filtered or unexported fields }
Table is a Span that writes its data in table form, with sizing controlled by the given table calculator. Rows are started with StartRow, followed by some calls to Column, followed by a call to EndRow. Once all rows are added, the table can be used as a Span.
func (*Table) SkipRow ¶
SkipRow prints a span without having it contribute to the table calculation.
func (*Table) StartRow ¶
func (t *Table) StartRow()
StartRow starts a new row. It must eventually be followed by EndRow.
func (*Table) VisualLength ¶
type TableCalculator ¶
TableCalculator calculates column widths (with optional padding) for a table based on the maximum required column width.
func (*TableCalculator) AddRowSizes ¶
func (c *TableCalculator) AddRowSizes(cellSizes ...int)
AddRowSizes registers a new row with cells of the given sizes.
func (*TableCalculator) ColumnWidths ¶
func (c *TableCalculator) ColumnWidths() []int
ColumnWidths calculates the appropriate column sizes given the previously registered rows.