termtable

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 3 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 termtable renders tabular data in five built-in styles: bordered (unicode box, default), rounded, ascii, markdown, and borderless padded columns for scripts. Rows normalize to the header width, empty tables render nothing, and unknown styles error.

The renderer is private under termtable/internal/table, written for this module: no third-party table code and no attribution duties surface in this API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Table)

Option tunes a Table at construction.

func WithStyle

func WithStyle(s Style) Option

WithStyle selects the look. Default StyleBordered.

type Style

type Style int

Style selects the table look. New styles arrive as new values; unknown values fail Render instead of silently picking one.

const (
	// StyleBordered is a unicode box table with full borders. Default.
	StyleBordered Style = iota
	// StyleRounded is StyleBordered with rounded corners.
	StyleRounded
	// StyleASCII is StyleBordered with plain ascii glyphs.
	StyleASCII
	// StyleMarkdown renders a pipe table with a header rule, for docs.
	StyleMarkdown
	// StyleBorderless renders padded columns without borders for scripts.
	StyleBorderless
)

func (Style) String

func (s Style) String() string

String names the style for errors and docs.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table buffers a header plus string rows and renders on demand.

func New

func New(w io.Writer, opts ...Option) *Table

New builds a Table writing to w with StyleBordered unless overridden.

func (*Table) AddRow

func (t *Table) AddRow(cols ...string)

AddRow appends one row.

func (*Table) AddRows

func (t *Table) AddRows(rows ...[]string)

AddRows appends many rows.

func (*Table) Render

func (t *Table) Render() error

Render draws the table with the selected style. Rows normalize to the header width (short rows pad empty, long rows truncate), matching script-friendly expectations on every style.

func (*Table) SetHeaders

func (t *Table) SetHeaders(cols ...string)

SetHeaders replaces the header row.

Directories

Path Synopsis
internal
table
Package table renders tables for termtable: a grid family (unicode, rounded, ascii, markdown) and borderless padded columns.
Package table renders tables for termtable: a grid family (unicode, rounded, ascii, markdown) and borderless padded columns.

Jump to

Keyboard shortcuts

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