table

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 4 Imported by: 183

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStyles

func DefaultStyles(_, _ int) lipgloss.Style

DefaultStyles is a TableStyleFunc that returns a new Style with no attributes.

Types

type Data

type Data interface {
	// At returns the contents of the cell at the given index.
	At(row, cell int) string

	// Rows returns the number of rows in the table.
	Rows() int

	// Columns returns the number of columns in the table.
	Columns() int
}

Data is the interface that wraps the basic methods of a table model.

type Filter

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

Filter applies a filter on some data.

func NewFilter

func NewFilter(data Data) *Filter

NewFilter initializes a new Filter.

func (*Filter) At

func (m *Filter) At(row, cell int) string

At returns the row at the given index.

func (*Filter) Columns

func (m *Filter) Columns() int

Columns returns the number of columns in the table.

func (*Filter) Filter

func (m *Filter) Filter(f func(row int) bool) *Filter

Filter applies the given filter function to the data.

func (*Filter) Rows

func (m *Filter) Rows() int

Rows returns the number of rows in the table.

type StringData

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

StringData is a string-based implementation of the Data interface.

func NewStringData

func NewStringData(rows ...[]string) *StringData

NewStringData creates a new StringData with the given number of columns.

func (*StringData) Append

func (m *StringData) Append(row []string)

Append appends the given row to the table.

func (*StringData) At

func (m *StringData) At(row, cell int) string

At returns the contents of the cell at the given index.

func (*StringData) Columns

func (m *StringData) Columns() int

Columns returns the number of columns in the table.

func (*StringData) Item

func (m *StringData) Item(rows ...string) *StringData

Item appends the given row to the table.

func (*StringData) Rows

func (m *StringData) Rows() int

Rows returns the number of rows in the table.

type StyleFunc

type StyleFunc func(row, col int) lipgloss.Style

StyleFunc is the style function that determines the style of a Cell.

It takes the row and column of the cell as an input and determines the lipgloss Style to use for that cell position.

Example:

t := table.New().
    Headers("Name", "Age").
    Row("Kini", 4).
    Row("Eli", 1).
    Row("Iris", 102).
    StyleFunc(func(row, col int) lipgloss.Style {
        switch {
           case row == 0:
               return HeaderStyle
           case row%2 == 0:
               return EvenRowStyle
           default:
               return OddRowStyle
           }
    })

type Table

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

Table is a type for rendering tables.

func New

func New() *Table

New returns a new Table that can be modified through different attributes.

By default, a table has no border, no styling, and no rows.

func (*Table) Border

func (t *Table) Border(border lipgloss.Border) *Table

Border sets the table border.

func (*Table) BorderBottom

func (t *Table) BorderBottom(v bool) *Table

BorderBottom sets the bottom border.

func (*Table) BorderColumn

func (t *Table) BorderColumn(v bool) *Table

BorderColumn sets the column border separator.

func (*Table) BorderHeader

func (t *Table) BorderHeader(v bool) *Table

BorderHeader sets the header separator border.

func (*Table) BorderLeft

func (t *Table) BorderLeft(v bool) *Table

BorderLeft sets the left border.

func (*Table) BorderRight

func (t *Table) BorderRight(v bool) *Table

BorderRight sets the right border.

func (*Table) BorderRow

func (t *Table) BorderRow(v bool) *Table

BorderRow sets the row border separator.

func (*Table) BorderStyle

func (t *Table) BorderStyle(style lipgloss.Style) *Table

BorderStyle sets the style for the table border.

func (*Table) BorderTop

func (t *Table) BorderTop(v bool) *Table

BorderTop sets the top border.

func (*Table) ClearRows

func (t *Table) ClearRows() *Table

ClearRows clears the table rows.

func (*Table) Data

func (t *Table) Data(data Data) *Table

Data sets the table data.

func (*Table) Headers

func (t *Table) Headers(headers ...string) *Table

Headers sets the table headers.

func (*Table) Height

func (t *Table) Height(h int) *Table

Height sets the table height.

func (*Table) Offset

func (t *Table) Offset(o int) *Table

Offset sets the table rendering offset.

func (*Table) Render

func (t *Table) Render() string

Render returns the table as a string.

func (*Table) Row

func (t *Table) Row(row ...string) *Table

Row appends a row to the table data.

func (*Table) Rows

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

Rows appends rows to the table data.

func (*Table) String

func (t *Table) String() string

String returns the table as a string.

func (*Table) StyleFunc

func (t *Table) StyleFunc(style StyleFunc) *Table

StyleFunc sets the style for a cell based on it's position (row, column).

func (*Table) Width

func (t *Table) Width(w int) *Table

Width sets the table width, this auto-sizes the columns to fit the width by either expanding or contracting the widths of each column as a best effort approach.

Jump to

Keyboard shortcuts

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