asciitable

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package asciitable renders caller-owned rows as ASCII tables.

It is intentionally independent of Spanner plan protobufs and plantree types: callers build rows from their own plan model, then provide column definitions and predicate accessors for the cells they want to show.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderAppendix

func RenderAppendix[T any](rows []T, spec AppendixSpec[T]) (string, error)

RenderAppendix formats an appendix for rows with associated items.

func RenderTable

func RenderTable[T any](rows []T, spec TableSpec[T]) (string, error)

RenderTable renders rows using spec.

func RenderTableless added in v0.3.0

func RenderTableless[T any](rows []T, spec TableSpec[T]) (string, error)

RenderTableless renders rows without headers or a table grid, using "|" as a one-character column separator. The separator is not escaped, so the output is intended for human display rather than machine parsing. Trailing empty cells are omitted from each physical line, while empty physical lines and entirely empty logical rows are preserved as blank output lines.

Right-aligned columns are left-padded to their own maximum content width; left-aligned columns are not padded, so wide text columns do not reintroduce table-grid width. Center alignment is not supported by this layout and is rendered as unpadded text.

Types

type Alignment

type Alignment string

Alignment controls horizontal alignment for a rendered column. The zero value means AlignLeft.

const (
	// AlignLeft left-aligns cell text. It is also the default when [Column.Alignment] is empty.
	AlignLeft Alignment = "left"
	// AlignRight right-aligns cell text.
	AlignRight Alignment = "right"
	// AlignCenter centers cell text.
	AlignCenter Alignment = "center"
)

type AppendixSpec

type AppendixSpec[T any] struct {
	// Title is printed before item lines. It must be non-empty.
	Title string
	// ID returns the non-negative display ID used in the appendix.
	ID func(row T) uint
	// Items returns the item lines associated with the row.
	Items func(row T) []string
}

AppendixSpec defines how appendices read row IDs and item lines.

type CellFunc

type CellFunc[T any] func(row T, index int) string

CellFunc returns one table cell for row at index.

type Column

type Column[T any] struct {
	// Header is the column header text.
	Header string
	// Alignment controls the cell alignment. The zero value uses [AlignLeft].
	Alignment Alignment
	// Cell returns the rendered cell text for each row.
	Cell CellFunc[T]
}

Column defines one rendered table column.

type TableSpec

type TableSpec[T any] struct {
	// Columns is the ordered list of table columns.
	Columns []Column[T]
}

TableSpec defines the columns of an ASCII table.

Jump to

Keyboard shortcuts

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