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 ¶
const ( RowModeTruncate = "truncate" RowModeWrap = "wrap" RowModeOverflow = "overflow" // default )
Variables ¶
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 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