Documentation
¶
Overview ¶
Package tableviewer renders terminal tables. The column resolution, width sampling and row streaming is handled by the go-c8y/v2 output table engine (encode.Table); this package contributes the go-c8y-cli specific pieces: cell formatting (number formatting, escaped paths), row fitting modes (truncate/wrap/overflow) and the tablewriter-based streaming renderer (StreamWriter).
Index ¶
- Constants
- Variables
- func CellFormatter(formatter numbers.NumberFormatter) encode.CellFormatter
- func CellTransform(rowMode string) encode.CellTransform
- func ColumnWidthRules(definition *dataview.Definition) func(name string) encode.ColumnWidthRule
- func TerminalWidth(defaultWidth int) int
- func WrapLine(line string, width int, wrapPrefix string) string
- type StreamWriter
Constants ¶
const ( RowModeTruncate = "truncate" RowModeWrap = "wrap" RowModeOverflow = "overflow" // default )
Variables ¶
var ArraySeparator = ", "
ArraySeparator is used to join the values of an array of scalars into a single table cell, e.g. [one, two]
var TextEllipsis = "…"
Functions ¶
func CellFormatter ¶ added in v2.55.1
func CellFormatter(formatter numbers.NumberFormatter) encode.CellFormatter
CellFormatter returns the cell extraction used for go-c8y-cli tables: column paths may contain special characters (escaped for gjson lookups), numbers are formatted with the given formatter and aligned right, and other values are rendered from their raw JSON representation
func CellTransform ¶ added in v2.55.1
func CellTransform(rowMode string) encode.CellTransform
CellTransform returns the cell fitting behavior for the given row mode: truncate (ellipsis marker), wrap (multi-line cells) or overflow (values are rendered untouched, the default)
func ColumnWidthRules ¶ added in v2.57.0
func ColumnWidthRules(definition *dataview.Definition) func(name string) encode.ColumnWidthRule
ColumnWidthRules returns the per-column width rules of a view definition for the table engine. nil is returned if the view does not define any widths
func TerminalWidth ¶ added in v2.55.1
TerminalWidth returns the usable width of the terminal, or defaultWidth when it can not be detected (e.g. output is not a terminal)
Types ¶
type StreamWriter ¶ added in v2.55.1
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter adapts tablewriter's streaming renderer to the go-c8y/v2 output table engine: the SDK side owns column resolution, width sampling and cell fitting (encode.Table) and hands resolved rows to this writer, which renders them incrementally — rows are written as they arrive instead of buffering the whole result set.
Usage:
err := output.Render(ctx, src,
encode.NewTableWithWriter(tableviewer.NewStreamWriter(os.Stdout, false), encode.TableOptions{
Columns: []string{"id", "name"},
}))
func NewStreamWriter ¶ added in v2.55.1
func NewStreamWriter(out io.Writer, enableColor bool) *StreamWriter
func (*StreamWriter) Close ¶ added in v2.55.1
func (s *StreamWriter) Close() error
func (*StreamWriter) WriteHeader ¶ added in v2.55.1
func (s *StreamWriter) WriteHeader(columns []encode.Column) error
WriteHeader receives the resolved columns (names, sampled widths and alignments) from the table engine and starts the underlying streaming table. Fixed per-column widths are required for streaming output (rows rendered early cannot be re-aligned), which is exactly what the engine's sampling provides.
func (*StreamWriter) WriteRow ¶ added in v2.55.1
func (s *StreamWriter) WriteRow(cells []string) error