asciitable

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 17, 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.

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