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
- func Header(l Layout) string
- func Join(cells []string) string
- func Pad(text string, width int, align Align) string
- func PadTrim(text string, width int, align Align, trim Trim) string
- func Truncate(text string, width int) string
- func TruncateLeft(text string, width int) string
- func TruncateMiddle(text string, width int) string
- type Align
- type Column
- type Layout
- type Trim
Constants ¶
const Ellipsis = "…"
Ellipsis replaces the tail of a cell that does not fit its column.
const Gutter = 2
Gutter is the number of blank cells rendered between two adjacent columns.
Variables ¶
This section is empty.
Functions ¶
func Header ¶
Header renders the column titles at their resolved widths, followed by the hidden-column marker when collapse dropped any. Callers style the result.
func Pad ¶
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 Truncate ¶
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 ¶
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 ¶
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 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 ¶
Layout is a resolved table: the columns that survived collapse, in render order, each with a final width.
func Fit ¶
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 ¶
FitCompact is Fit for a table with no room to spare: what collapse hides goes unmarked, so every cell of the row carries content.