Documentation
¶
Index ¶
- Constants
- type Column
- type KeyMap
- type Metadata
- type Model
- func (m *Model) Blur()
- func (m Model) Columns() []Column
- func (m Model) Cursor() int
- func (m *Model) Find(text string, startRow int) bool
- func (m *Model) Focus()
- func (m Model) Focused() bool
- func (m *Model) FromValues(value, separator string)
- func (m Model) GetRow(obj Metadata) int
- func (m Model) GetRowByHash(hashCode uint64) int
- func (m *Model) GotoBottom()
- func (m *Model) GotoTop()
- func (m Model) Height() int
- func (m Model) HelpView() string
- func (m *Model) MoveDown(n int)
- func (m *Model) MoveUp(n int)
- func (m *Model) RemoveRow(obj Metadata) bool
- func (m *Model) RemoveRowByHash(hashCode uint64) bool
- func (m *Model) RemoveRowByIndex(index int) bool
- func (m *Model) RemoveSelectedRow() bool
- func (m *Model) RenumberRows()
- func (m Model) Rows() []Row
- func (m Model) SelectedRow() Row
- func (m Model) SelectedRowYOffset() int
- func (m *Model) SetColumns(c []Column)
- func (m *Model) SetCursor(n int)
- func (m *Model) SetHeight(h int)
- func (m *Model) SetRows(r []Row)
- func (m *Model) SetStyles(s Styles)
- func (m *Model) SetWidth(w int)
- func (m *Model) SortBy(index int, order SortOrder, typeHint interface{})
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m *Model) UpdateViewport()
- func (m Model) View() string
- func (m Model) Width() int
- type Option
- func WithColumns(cols []Column) Option
- func WithFocused(f bool) Option
- func WithHeight(h int) Option
- func WithKeyMap(km KeyMap) Option
- func WithRowNumbers() Option
- func WithRows(rows []Row) Option
- func WithStructData(data interface{}, fields ...string) Option
- func WithStyles(s Styles) Option
- func WithWidth(w int) Option
- type Row
- type SortOrder
- type Styles
Constants ¶
const ( SortAscending SortOrder = false SortDescending SortOrder = true SortString = "" SortNumeric = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyMap ¶
type KeyMap struct { LineUp key.Binding LineDown key.Binding PageUp key.Binding PageDown key.Binding HalfPageUp key.Binding HalfPageDown key.Binding GotoTop key.Binding GotoBottom key.Binding }
KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which is used to render the help menu.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns a default set of keybindings.
type Metadata ¶ added in v0.2.0
type Metadata interface { // GetHashCode returns a unique hash for the row metadata. // It should remain constant for the lifetime of the table. // You can use something that implements the Hash64 interface to generate this GetHashCode() uint64 }
Metadata must be implemented by any metadata associated with a table row, usually the source data associated with the row.
type Model ¶
Model defines a state for the table widget.
func (*Model) Find ¶
Find performs a free text search of the table data for the given string, beginning from startRow+1 or cursor+1 whichever is sooner, to the end of the table. Cursor is moved to the first match. If no match is found, false is returned.
func (*Model) Focus ¶
func (m *Model) Focus()
Focus focuses the table, allowing the user to move around the rows and interact.
func (*Model) FromValues ¶
FromValues create the table rows from a simple string. It uses `\n` by default for getting all the rows and the given separator for the fields on each row.
func (Model) GetRow ¶ added in v0.2.0
GetRow returns the index of the row containing the given object as metadata. If the row is not found, -1 is returned.
func (Model) GetRowByHash ¶ added in v0.2.0
GetRowByHash returns the index of the row identified by the given hash value. If the row is not found, -1 is returned.
func (*Model) GotoBottom ¶
func (m *Model) GotoBottom()
GotoBottom moves the selection to the last row.
func (Model) HelpView ¶
HelpView is a helper method for rendering the help menu from the keymap. Note that this view is not rendered by default and you must call it manually in your application, where applicable.
func (*Model) MoveDown ¶
MoveDown moves the selection down by any number of rows. It can not go below the last row.
func (*Model) MoveUp ¶
MoveUp moves the selection up by any number of rows. It can not go above the first row.
func (*Model) RemoveRow ¶ added in v0.2.0
RemoveRow removes the row containing the given object as metadata
func (*Model) RemoveRowByHash ¶ added in v0.2.0
RemoveRowByHash removes the row identified by the metadata hash value. If no rows remain, this returns false.
func (*Model) RemoveRowByIndex ¶ added in v0.2.0
RemoveRowByIndex removes the row at the given index. If no rows remain, this returns false.
func (*Model) RemoveSelectedRow ¶
RemoveSelectedRow removes the currently selected row. If no rows remain, this returns false.
func (*Model) RenumberRows ¶
func (m *Model) RenumberRows()
RenumberRows renumbers the row numbers in column 0, if row numbers were requested in the constructor options.
func (Model) SelectedRow ¶
SelectedRow returns the selected row. You can cast it to your own implementation.
func (Model) SelectedRowYOffset ¶
SelectedRowYOffset returns the offset in console lines of the selected row from the top of the viewport. If the top line is selected, this value is zero; if the second line is selected, the value is 1 etc.
func (*Model) SetColumns ¶
SetColumns sets a new columns state.
func (*Model) SortBy ¶
SortBy sorts the table by column identified by 'index' and in the given order.
typeHint hints what data type should be assumed for the column. Pass empty string to string-sort, 0 to numerically sort (all numeric types). If the data cannot be cast to a numeric type when requested, then it will string sort the displayed data.
func (*Model) UpdateViewport ¶
func (m *Model) UpdateViewport()
UpdateViewport updates the list content based on the previously defined columns and rows.
type Option ¶
type Option func(*Model)
Option is used to set options in New. For example:
table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))
func WithColumns ¶
WithColumns sets the table columns (headers).
func WithRowNumbers ¶
func WithRowNumbers() Option
WithRowNumbers insetrs a column at postion zero containing row numbers.
func WithStructData ¶ added in v0.2.0
WithStructData creates a table by reflecting a slice of structs implementing the Metadata interface.
- Column names are derived from struct field names or if present, the value of struct tag "xtable".
- Row data is converted to strings from the data in the slice.
- Row Metadata field is set to the values in the slice.
- All public struct fields are included, unless constrained by field names listed in `fields` argument.
Panics if there is any error parsing the data from the slice, such as
- data is not a slice of structs
- slice element does not implement Metadata
type Styles ¶
Styles contains style definitions for this list component. By default, these values are generated by DefaultStyles.
func DefaultStyles ¶
func DefaultStyles() Styles
DefaultStyles returns a set of default style definitions for this table.