Documentation
¶
Overview ¶
package tabula is a rudimentary library for rendering tables in the terminal.
It uses lipgloss for styling and can be dynamically rendered with bubbletea.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // HeaderCharacter is the string used to render the header's horizontal // border. Override to customize the header border style. HeaderCharacter string = "=" // SummaryRowCharacter is the string used to render the summary row's // horizontal border. Override to customize the summary row border style. SummaryRowCharacter string = "-" // RowBorderCharacter is the string used to render the vertical border between // columns. Override to customize the column border style. RowBorderCharacter string = "│" // DefaultCellPadding is the default horizontal padding applied to the left and // right of each cell. Can be overridden per column via [WithPadding]. Override // this variable to change the default padding for all columns that don't // explicitly set a padding. DefaultCellPadding uint = 2 // DefaultCellAlignment is the default horizontal alignment of cell content // within a column. This can be overridden for each column individually by // setting the [Table.WithAlignment] property. Override this variable to change // the default alignment for all columns that don't explicitly set an // alignment. DefaultCellAlignment = lipgloss.Left )
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column defines the properties of a single column in the table, including its header text. Create a new instance with NewColumn and configure it with the available [ColumnOption]s.
type ColumnOption ¶
type ColumnOption func(*Column)
func WithAlignment ¶
func WithAlignment(alignment lipgloss.Position) ColumnOption
WithAlignment sets the alignment of the column's content within each cell to the given lipgloss.Position. If not set, defaults to DefaultCellAlignment.
func WithLeftBorder ¶
func WithLeftBorder() ColumnOption
WithLeftBorder adds the left border character RowBorderCharacter to the column. WithRightBorder can safely be called on the left-adjacent column without causing a double border.
func WithMaxWidth ¶
func WithMaxWidth() ColumnOption
WithMaxWidth sets the column to grow in width until the table width is filled. This is similiar to CSS's `flex-grow: 1` property. This is especially useful for spacing where a limited subset of columns should stick to the right of the table. If multiple columns have this property enabled, they will share this remaining table width equally.
func WithPadding ¶
func WithPadding(left, right uint) ColumnOption
WithPadding sets the left and right padding for the column's cells. If not set, defaults to DefaultCellPadding on both sides.
func WithRightBorder ¶
func WithRightBorder() ColumnOption
WithRightBorder adds the right border character RowBorderCharacter to the column. WithLeftBorder can safely be called on the right-adjacent column without causing a double border.
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row carries the content of a single row in the table. Create a new instance with NewRow.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a structure that defines [Column]s and [Row]s, and is responsible for rendering them as a cohesive table. Create a new instance with New, add rows after instantiation with Table.AddRow, and then render the table with Table.Render or Table.String.
func New ¶
func New(cols []Column, opts ...TableOption) *Table
New creates a new Table with the given [Column]s.
func (*Table) AddRow ¶
AddRow adds a new Row to the Table. If the number of cells in the row does not match the number of columns in the table, an error is returned.
func (*Table) AddSummary ¶
AddSummary sets a summary Row for the Table, which is rendered at the end of the table.
func (*Table) String ¶
String renders the table as a string. Same as Table.Render.
type TableOption ¶
type TableOption func(*Table)
func WithFixedWidth ¶
func WithFixedWidth(width uint) TableOption
WithFixedWidth sets a fixed width for the table, which is used for rendering. By default, the table uses the terminal width as its width.