stickers

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 9 Imported by: 14

README ΒΆ

Stickers πŸ‘Ύ

Is a collection of TUI elements, FlexBox and Table at the moment, its build for bubbletea using lipgloss.

Demo

Flex Box πŸ“¦

Responsive grid box insipred by CSS flexbox.
Easy to create responsive grids that scale using ratios between these elements. FlexBox Simple Demo

Table 🍰

Responsive, x/y scrollable, sortable table using FlexBox.
Tabel viewer with ability to get the content of the cell over which the cursor is placed at and sort the data by column. Sorting supports basic number and string type so number sorting is possible πŸŽ‰ Table Multi-Type Demo

TODO
  • filtering βœ…
  • sorting βœ…

Known issues

Table selected cell is not rendering background color correctly, will be fixed with https://github.com/charmbracelet/lipgloss/pull/69


Made with Charm.

The Charm logo

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	TableSortingAscending  = 0
	TableSortingDescending = 1
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type FlexBox ΒΆ

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

FlexBox responsive box grid insipred by CSS flexbox

func NewFlexBox ΒΆ

func NewFlexBox(width, height int) *FlexBox

NewFlexBox initialize FlexBox object with defaults

func (*FlexBox) AddRows ΒΆ

func (r *FlexBox) AddRows(rows []*FlexBoxRow) *FlexBox

AddRows appends additional rows to the FlexBox

func (*FlexBox) ForceRecalculate ΒΆ

func (r *FlexBox) ForceRecalculate()

ForceRecalculate forces the recalculation for the box and all the rows

func (*FlexBox) GetHeight ΒΆ

func (r *FlexBox) GetHeight() int

GetHeight yields current FlexBox height

func (*FlexBox) GetRow ΒΆ

func (r *FlexBox) GetRow(index int) (row FlexBoxRow, exists bool)

GetRow returns the FlexBoxRow on the given index if it exists note: it does not return a pointer

func (*FlexBox) GetWidth ΒΆ

func (r *FlexBox) GetWidth() int

GetWidth yields current FlexBox width

func (*FlexBox) LockRowHeight ΒΆ

func (r *FlexBox) LockRowHeight(value int) *FlexBox

LockRowHeight sets the fixed height value for all the rows this will disable vertical scaling

func (*FlexBox) MustGetRow ΒΆ

func (r *FlexBox) MustGetRow(index int) FlexBoxRow

MustGetRow same as GetRow only panics if row does not exist

func (*FlexBox) NewRow ΒΆ

func (r *FlexBox) NewRow() *FlexBoxRow

NewRow initialize a new FlexBoxRow with width inherited from the FlexBox

func (*FlexBox) Render ΒΆ

func (r *FlexBox) Render() string

Render initiates the recalculation of the rows dimensions(height) if the recalculate flag is on, and then it renders all the rows and combines them on the vertical axis

func (*FlexBox) Row ΒΆ

func (r *FlexBox) Row(index int) *FlexBoxRow

Row returns the FlexBoxRow on the given index if it exists note: forces the recalculation if found

func (*FlexBox) RowsLen ΒΆ

func (r *FlexBox) RowsLen() int

RowsLen returns the len of the rows slice

func (*FlexBox) SetHeight ΒΆ

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

SetHeight sets the FlexBox height

func (*FlexBox) SetRows ΒΆ

func (r *FlexBox) SetRows(rows []*FlexBoxRow) *FlexBox

SetRows replace rows on the FlexBox

func (*FlexBox) SetStyle ΒΆ

func (r *FlexBox) SetStyle(style lipgloss.Style) *FlexBox

SetStyle replaces the style, it unsets width/height related keys

func (*FlexBox) SetWidth ΒΆ

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

SetWidth sets the FlexBox width

func (*FlexBox) StylePassing ΒΆ

func (r *FlexBox) StylePassing(value bool) *FlexBox

StylePassing set whether the style should be passed to the rows

func (*FlexBox) UpdateRow ΒΆ

func (r *FlexBox) UpdateRow(index int, row *FlexBoxRow) *FlexBox

UpdateRow replaces the FlexBoxRow on the given index

type FlexBoxCell ΒΆ

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

FlexBoxCell is a building block object of the FlexBox, it represents a single cell within a box cells are stacked horizontally

func NewFlexBoxCell ΒΆ

func NewFlexBoxCell(ratioX, ratioY int) *FlexBoxCell

NewFlexBoxCell initialize FlexBoxCell object with defaults

func (*FlexBoxCell) GetContent ΒΆ

func (r *FlexBoxCell) GetContent() string

GetContent returns the cells raw content

func (*FlexBoxCell) GetHeight ΒΆ

func (r *FlexBoxCell) GetHeight() int

GetHeight returns real height of the cell

func (*FlexBoxCell) GetStyle ΒΆ

func (r *FlexBoxCell) GetStyle() lipgloss.Style

GetStyle returns the copy of the cells current style

func (*FlexBoxCell) GetWidth ΒΆ

func (r *FlexBoxCell) GetWidth() int

GetWidth returns real width of the cell

func (*FlexBoxCell) SetContent ΒΆ

func (r *FlexBoxCell) SetContent(content string) *FlexBoxCell

SetContent sets the cells content

func (*FlexBoxCell) SetID ΒΆ

func (r *FlexBoxCell) SetID(id string) *FlexBoxCell

SetID sets the cells ID

func (*FlexBoxCell) SetMinWidth ΒΆ

func (r *FlexBoxCell) SetMinWidth(value int) *FlexBoxCell

SetMinWidth sets the cells minimum width, this will not disable responsivness

func (*FlexBoxCell) SetStyle ΒΆ

func (r *FlexBoxCell) SetStyle(style lipgloss.Style) *FlexBoxCell

SetStyle replaces the style, it unsets width/height related keys

type FlexBoxRow ΒΆ

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

FlexBoxRow is the container for the cells, this object has the least to do with the ratio of the construction as it takes all of the needed ratio information from the cell slice rows are stacked vertically

func (*FlexBoxRow) AddCells ΒΆ

func (r *FlexBoxRow) AddCells(cells []*FlexBoxCell) *FlexBoxRow

AddCells appends the cells to the row if the cell ID is not set it will default to the index of the cell

func (*FlexBoxRow) Cell ΒΆ

func (r *FlexBoxRow) Cell(index int) *FlexBoxCell

Cell returns the FlexBoxCell on the given index if it exists note: forces the recalculation if found

func (*FlexBoxRow) CellsLen ΒΆ

func (r *FlexBoxRow) CellsLen() int

CellsLen returns the len of the cells slice

func (*FlexBoxRow) GetCellWithID ΒΆ

func (r *FlexBoxRow) GetCellWithID(id string) (cell FlexBoxCell, exists bool)

GetCellWithID returns the cell with the given ID if existing

func (*FlexBoxRow) GetCellWithIndex ΒΆ

func (r *FlexBoxRow) GetCellWithIndex(index int) (cell FlexBoxCell, exists bool)

GetCellWithIndex returns the cell with the given index if existing note: it does not return a pointer

func (*FlexBoxRow) MustGetCellWithIndex ΒΆ

func (r *FlexBoxRow) MustGetCellWithIndex(index int) FlexBoxCell

MustGetCellWithIndex returns the cell with the given index if existing, panic if not note: it does not return a pointer

func (*FlexBoxRow) SetStyle ΒΆ

func (r *FlexBoxRow) SetStyle(style lipgloss.Style) *FlexBoxRow

SetStyle replaces the style, it unsets width/height related keys

func (*FlexBoxRow) StylePassing ΒΆ

func (r *FlexBoxRow) StylePassing(value bool) *FlexBoxRow

StylePassing set whether the style should be passed to the cells

func (*FlexBoxRow) UpdateCellWithIndex ΒΆ

func (r *FlexBoxRow) UpdateCellWithIndex(index int, cell *FlexBoxCell)

UpdateCellWithIndex replaces the cell on the given index if it exists if its not existing no changes will apply

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) 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
)

Directories ΒΆ

Path Synopsis
example

Jump to

Keyboard shortcuts

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