Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMaxRowWidth is the default maximum width for table row cells. // Messages longer than this will be wrapped at word boundaries. DefaultMaxRowWidth = 100 )
Variables ¶
var DefaultTableOptions = []tablewriter.Option{ tablewriter.WithHeaderAlignment(tw.AlignLeft), tablewriter.WithRowAutoWrap(tw.WrapNormal), tablewriter.WithRowMaxWidth(DefaultMaxRowWidth), tablewriter.WithRendition(tw.Rendition{ Settings: tw.Settings{ Separators: tw.Separators{ BetweenColumns: tw.Off, BetweenRows: tw.Off, }, Lines: tw.Lines{ ShowTop: tw.On, ShowBottom: tw.On, ShowHeaderLine: tw.On, }, }, }), }
DefaultTableOptions provides a clean, minimal table style with left-aligned headers and no borders or separators.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column represents a table column with its header name and optional formatters. Multiple formatters can be chained and will be applied in sequence.
func (Column) Fn ¶
func (c Column) Fn(formatter ColumnFormatter) Column
Fn appends a custom Go function formatter to this column's formatter chain. Can be chained with other formatters: Column().JQ(...).Fn(...)
type ColumnFormatter ¶
ColumnFormatter is a function that transforms a value for display in a specific column.
func ChainFormatters ¶
func ChainFormatters(formatters ...ColumnFormatter) ColumnFormatter
ChainFormatters composes multiple formatters into a single formatter pipeline. The output of each formatter is passed as input to the next formatter. This enables building transformation pipelines like: JQ extraction → colorization → truncation.
func JQFormatter ¶
func JQFormatter(query string) ColumnFormatter
JQFormatter creates a ColumnFormatter that executes a jq query on the input value. Uses the jq.Query utility which properly handles unstructured types.
type Option ¶
Option is a functional option for configuring a Renderer.
func WithFormatter ¶
func WithFormatter[T any](columnName string, formatter ColumnFormatter) Option[T]
WithFormatter adds a column-specific formatter function.
func WithHeaders ¶
WithHeaders sets the column headers for the table.
func WithTableOptions ¶
func WithTableOptions[T any](values ...tablewriter.Option) Option[T]
WithTableOptions sets the underlying tablewriter options.
type Renderer ¶
type Renderer[T any] struct { // contains filtered or unexported fields }
Renderer provides a flexible interface for creating and rendering tables. T is the type of objects that will be appended to the table.
func NewRenderer ¶
NewRenderer creates a new table renderer with the given tableOptions.
func NewWithColumns ¶
NewWithColumns creates a new table renderer with columns defined using the fluent API. This provides a more declarative way to define tables with JQ queries or custom formatters. Supports chaining formatters: Column().JQ(...).Fn(...)
Example:
renderer := table.NewWithColumns(os.Stdout,
table.NewColumn("NAME").JQ(".metadata.name").Fn(strings.ToUpper),
table.NewColumn("TYPE").JQ(".kind"),
table.NewColumn("READY").JQ(`.status.conditions[] | select(.type=="Ready") | .status // "Unknown"`),
)
func (*Renderer[T]) Append ¶
Append adds a single row to the table. Accepts either []any (legacy) or a struct (auto-extracted via mapstructure).
func (*Renderer[T]) AppendAll ¶
AppendAll adds multiple rows to the table in a single operation. Each item in the slice can be either []any or a struct.
func (*Renderer[T]) GetHeaders ¶
GetHeaders returns the currently configured table headers.
func (*Renderer[T]) SetHeaders ¶
SetHeaders configures table headers dynamically after renderer creation.