tableviewer

package
v2.59.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 ArraySeparator = ", "

ArraySeparator is used to join the values of an array of scalars into a single table cell, e.g. [one, two]

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

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