table

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableSortingAscending  = 0
	TableSortingDescending = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Ordered

type Ordered interface {
	int | int8 | int32 | int16 | int64 | float32 | float64 | string
}

type Table

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

Table responsive, x/y scrollable table that uses magic of FlexBox

func NewTable

func NewTable(width, height int, columnHeaders []string) *Table

NewTable initialize Table object with defaults

func (*Table) AddRows

func (r *Table) AddRows(rows [][]any) (*Table, error)

AddRows add multiple rows, will return error on the first instance of a row that does not match the type set on table will update rows only when there are no errors

func (*Table) CursorDown

func (r *Table) CursorDown() *Table

CursorDown move table cursor down

func (*Table) CursorLeft

func (r *Table) CursorLeft() *Table

CursorLeft move table cursor left

func (*Table) CursorRight

func (r *Table) CursorRight() *Table

CursorRight move table cursor right

func (*Table) CursorUp

func (r *Table) CursorUp() *Table

CursorUp move table cursor up

func (*Table) GetCursorLocation

func (r *Table) GetCursorLocation() (int, int)

GetCursorLocation returns the current x,y position of the cursor

func (*Table) GetCursorValue

func (r *Table) GetCursorValue() string

GetCursorValue returns the string of the cell under the cursor

func (*Table) GetFilter

func (r *Table) GetFilter() (columnIndex int, s string)

GetFilter returns string used for filtering and the column index TODO: enable multi column filtering

func (*Table) MustAddRows

func (r *Table) MustAddRows(rows [][]any) *Table

MustAddRows executes AddRows and panics if there is an error

func (*Table) OrderByColumn

func (r *Table) OrderByColumn(index int) *Table

OrderByColumn orders rows by a column with the index n, simple bubble sort, nothing too fancy does not apply when there is less than 2 row in a table TODO: this messes up numbering that one might use, implement automatic indexing of rows TODO: allow user to disable ordering

func (*Table) Render

func (r *Table) Render() string

Render renders the table into the string

func (*Table) SetFilter

func (r *Table) SetFilter(columnIndex int, s string) *Table

SetFilter sets filtering string on a column

func (*Table) SetHeight

func (r *Table) SetHeight(value int) *Table

SetHeight sets the height of the table including the header and footer

func (*Table) SetMinWidth

func (r *Table) SetMinWidth(values []int) *Table

SetMinWidth replaces the minimum width slice, it has to be exactly the len of the headers/rows slices if it's not matching len it will trigger fatal error

func (*Table) SetRatio

func (r *Table) SetRatio(values []int) *Table

SetRatio replaces the ratio slice, it has to be exactly the len of the headers/rows slices also each value have to be greater than 0, if either fails we panic

func (*Table) SetStylePassing

func (r *Table) SetStylePassing(value bool) *Table

SetStylePassing sets the style passing flag, if true, styles are passed all the way down from box to cell

func (*Table) SetStyles

func (r *Table) SetStyles(styles map[TableStyleKey]lipgloss.Style) *Table

SetStyles allows overrides of styling elements of the table When only a partial set of overrides are provided, the default styling will be used

func (*Table) SetTypes

func (r *Table) SetTypes(columnTypes ...any) (*Table, error)

SetTypes sets the column type, setting this will remove all the rows so make sure you do it when instantiating Table object or add new rows after this, types have to be one of Ordered interface types

func (*Table) SetWidth

func (r *Table) SetWidth(value int) *Table

SetWidth sets the width of the table

func (*Table) UnsetFilter

func (r *Table) UnsetFilter() *Table

UnsetFilter resets filtering

type TableBadCellTypeError

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

TableBadCellTypeError type of cell does not match type of column

func (TableBadCellTypeError) Error

func (e TableBadCellTypeError) Error() string

type TableBadTypeError

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

TableBadTypeError type does not match Ordered interface types

func (TableBadTypeError) Error

func (e TableBadTypeError) Error() string

type TableRowLenError

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

TableRowLenError row length is not matching headers len

func (TableRowLenError) Error

func (e TableRowLenError) Error() string

type TableSingleType

type TableSingleType[T Ordered] struct {
	Table
}

TableSingleType is Table that is using only 1 type for rows allowing for easier AddRows with fewer errors

func NewTableSingleType

func NewTableSingleType[T Ordered](width, height int, columnHeaders []string) *TableSingleType[T]

NewTableSingleType initialize TableSingleType object with defaults

func (*TableSingleType[T]) AddRows

func (r *TableSingleType[T]) AddRows(rows [][]T) *TableSingleType[T]

func (*TableSingleType[T]) MustAddRows

func (r *TableSingleType[T]) MustAddRows(rows [][]T) *TableSingleType[T]

func (*TableSingleType[T]) SetTypes

func (r *TableSingleType[T]) SetTypes()

SetTypes overridden for TableSimple

type TableSortingOrderKey

type TableSortingOrderKey int

type TableStyleKey

type TableStyleKey int
const (
	TableHeaderStyleKey TableStyleKey = iota
	TableFooterStyleKey
	TableRowsStyleKey
	TableRowsSubsequentStyleKey
	TableRowsCursorStyleKey
	TableCellCursorStyleKey
)

Jump to

Keyboard shortcuts

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