tableviewer

package
v2.55.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const (
	RowModeTruncate = "truncate"
	RowModeWrap     = "wrap"
	RowModeOverflow = "overflow" // default
)

Variables

View Source
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

func TerminalWidth(defaultWidth int) int

TerminalWidth returns the usable width of the terminal, or defaultWidth when it can not be detected (e.g. output is not a terminal)

func WrapLine added in v2.18.0

func WrapLine(line string, width int, wrapPrefix string) string

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL