table

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package table fits a set of columns into an available terminal width and pads cells to it. Every measurement is in display cells via lipgloss.Width, so wide glyphs never shift a row.

Index

Constants

View Source
const Ellipsis = "…"

Ellipsis replaces the tail of a cell that does not fit its column.

View Source
const Gutter = 2

Gutter is the number of blank cells rendered between two adjacent columns.

Variables

This section is empty.

Functions

func Header(l Layout) string

Header renders the column titles at their resolved widths, followed by the hidden-column marker when collapse dropped any. Callers style the result.

func Join

func Join(cells []string) string

Join concatenates already-padded cells with the standard gutter.

func Pad

func Pad(text string, width int, align Align) string

Pad truncates text to width display cells, appending an ellipsis when one fits, and pads the remainder to exactly width on the side align implies.

func PadTrim

func PadTrim(text string, width int, align Align, trim Trim) string

PadTrim is Pad with the cut taken from the end trim names.

func Truncate

func Truncate(text string, width int) string

Truncate shortens text to at most width display cells, marking the cut with an ellipsis whenever the result still leaves room for content.

func TruncateLeft

func TruncateLeft(text string, width int) string

TruncateLeft shortens text to at most width display cells by removing its head, so the tail survives the cut. Use it where a shared prefix carries no information, such as a batch result's repo path.

func TruncateMiddle

func TruncateMiddle(text string, width int) string

TruncateMiddle shortens text to at most width display cells by removing its middle, so both ends survive the cut. Use it where the tail carries as much meaning as the head, such as a line of prose or a long path.

Types

type Align

type Align int

Align selects which side of its column a cell's text sits against.

const (
	AlignLeft Align = iota
	AlignRight
)

Cell alignments. Text reads better left-aligned; counts and ages read better right-aligned against the next gutter.

type Column

type Column struct {
	Key      string
	Title    string
	Min      int
	Max      int
	Weight   int
	Priority int
	Align    Align
	Trim     Trim
}

Column describes one column of a table.

Priority orders collapse: the lowest positive Priority is hidden first, so a column's Priority is its information value. Zero means the column is never hidden and the table overflows instead. Max of zero is unbounded.

type Layout

type Layout struct {
	Columns []Column
	Hidden  int
	// contains filtered or unexported fields
}

Layout is a resolved table: the columns that survived collapse, in render order, each with a final width.

func Fit

func Fit(cols []Column, width int) Layout

Fit resolves cols into width display cells. Columns are hidden by ascending Priority until the remaining minimums fit, then the surplus is shared between the weighted columns in proportion to their Weight and capped at their Max.

func FitCompact

func FitCompact(cols []Column, width int) Layout

FitCompact is Fit for a table with no room to spare: what collapse hides goes unmarked, so every cell of the row carries content.

func (Layout) Marker

func (l Layout) Marker() string

Marker announces how many columns collapse hid, or is empty when none were.

func (Layout) Total

func (l Layout) Total() int

Total returns the display width the laid-out row occupies, including gutters and the hidden-column marker.

func (Layout) Width

func (l Layout) Width(key string) int

Width returns the resolved width of the named column, or zero when it was hidden or is not part of the table.

type Trim

type Trim int

Trim selects which end of a cell is dropped when its text is too wide for its column.

const (
	TrimRight Trim = iota
	TrimLeft
)

Cell truncation ends. Most text reads from the left, so the tail is what goes; a name whose prefix is shared with every other name in the column reads the other way.

Jump to

Keyboard shortcuts

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