Documentation
¶
Overview ¶
TablePrinter facilitates rendering column-formatted data to a terminal and TSV-formatted data to a script or a file. It is suitable for presenting tabular data in a human-readable format that is guaranteed to fit within the given viewport, while at the same time offering the same data in a machine-readable format for scripts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FieldOption ¶
type FieldOption func(*tableField)
func WithColor ¶
func WithColor(fn func(string) string) FieldOption
WithColor sets the color function for the field. The function should transform a string value by wrapping it in ANSI escape codes. The color function will not be used if the table was initialized in non-terminal mode.
func WithTruncate ¶
func WithTruncate(fn func(int, string) string) FieldOption
WithTruncate overrides the truncation function for the field. The function should transform a string argument into a string that fits within the given display width. The default behavior is to truncate the value by adding "..." in the end. Pass nil to disable truncation for this value.
type JSONPrinter ¶
type JSONPrinter interface {
Printer
}
func NewJSONPrinter ¶
func NewJSONPrinter(w io.Writer) (jp JSONPrinter, err error)
NewJSONPrinter initializes a table printer with terminal mode and terminal width. When terminal mode is enabled, the output will be human-readable, column-formatted to fit available width, and rendered with color support. In non-terminal mode, the output is tab-separated and all truncation of values is disabled.
type ListPrinter ¶ added in v0.2.0
type ListPrinter interface {
Printer
}
ListPrinter prints data as a list of key/value lines per object, separated by a blank line.
func NewListPrinter ¶ added in v0.2.0
func NewListPrinter(w io.Writer) (lp ListPrinter, err error)
type TablePrinter ¶
type TablePrinter interface {
Printer
}
func NewTablePrinter ¶
NewTablePrinter initializes a table printer with terminal mode and terminal width. When terminal mode is enabled, the output will be human-readable, column-formatted to fit available width, and rendered with color support. In non-terminal mode, the output is tab-separated and all truncation of values is disabled.
type UnsupportedPrinterError ¶
type UnsupportedPrinterError struct {
// contains filtered or unexported fields
}
func (*UnsupportedPrinterError) Error ¶
func (e *UnsupportedPrinterError) Error() string