gowid: github.com/gcla/gowid/widgets/table Index | Files

package table

import "github.com/gcla/gowid/widgets/table"

A simple implementation of a CSV table widget.

Package table provides a widget that renders tabular output.


Package Files

simple_model.go table.go

func Focus Uses

func Focus(t IFocus) list.IWalkerPosition


func RowToWidget Uses

func RowToWidget(t IRowToWidget, ws []gowid.IWidget) gowid.IWidget

func SetFocus Uses

func SetFocus(t ISetFocus, pos list.IWalkerPosition)

In order to implement list.IWalker

func SimpleCellWidget Uses

func SimpleCellWidget(c ISimpleRowProvider, i int, s string) gowid.IWidget

Provides a "cell" which is stitched together with columns to provide a "row"

func SimpleCellWidgets Uses

func SimpleCellWidgets(c ISimpleDataProvider, row2 RowId) []gowid.IWidget

func WidgetAt Uses

func WidgetAt(t IWidgetAt, pos int) gowid.IWidget

Provide the pos'th "row" widget

type BoundedWidget Uses

type BoundedWidget struct {

func (*BoundedWidget) BoundedWalker Uses

func (w *BoundedWidget) BoundedWalker() list.IBoundedWalker

func (*BoundedWidget) First Uses

func (w *BoundedWidget) First() list.IWalkerPosition

func (*BoundedWidget) Last Uses

func (w *BoundedWidget) Last() list.IWalkerPosition

func (*BoundedWidget) Length Uses

func (w *BoundedWidget) Length() int

func (*BoundedWidget) Pos Uses

func (w *BoundedWidget) Pos() int

func (*BoundedWidget) SetPos Uses

func (w *BoundedWidget) SetPos(pos list.IBoundedWalkerPosition, app gowid.IApp)

type Coords Uses

type Coords struct {
    Column int
    Row    int

func (Coords) String Uses

func (c Coords) String() string

type FloatCompare Uses

type FloatCompare struct{}

FloatCompare is a unit type that satisfies ICompare, and can be used for numerically comparing float64 values.

func (FloatCompare) Less Uses

func (s FloatCompare) Less(i, j string) bool

type IBoundedModel Uses

type IBoundedModel interface {
    Rows() int

IBoundedTable implements ITable and can also provide the total number of rows in the table.

type ICompare Uses

type ICompare interface {
    Less(i, j string) bool

ICompare is the type of the compare function used when sorting a table's rows.

type IFocus Uses

type IFocus interface {
    AtRow(int) gowid.IWidget
    CurrentRow() int

type IGoToBottom Uses

type IGoToBottom interface {
    GoToBottom(app gowid.IApp)

type IGoToMiddle Uses

type IGoToMiddle interface {
    GoToMiddle(app gowid.IApp)

type IInvertible Uses

type IInvertible interface {
    IdentifierToRow(rowid RowId) (int, bool)

type IMakeHeader Uses

type IMakeHeader interface {
    HeaderWidget([]gowid.IWidget, int) gowid.IWidget

type IModel Uses

type IModel interface {
    Columns() int
    RowIdentifier(row int) (RowId, bool)   // return a unique ID for row
    CellWidgets(row RowId) []gowid.IWidget // nil means EOD
    HeaderWidgets() []gowid.IWidget        // nil means no headers
    VerticalSeparator() gowid.IWidget
    HorizontalSeparator() gowid.IWidget
    HeaderSeparator() gowid.IWidget
    Widths() []gowid.IWidgetDimension

IModel is implemented by any type which can provide arrays of widgets for a given table row, and optionally header widgets.

type IRowToWidget Uses

type IRowToWidget interface {
    VertDivider() gowid.IContainerWidget
    Model() IModel
    Cache() *lru.Cache

type ISetFocus Uses

type ISetFocus interface {
    SetCurrentRow(pos Position)

type ISimpleDataProvider Uses

type ISimpleDataProvider interface {
    GetData() [][]string
    CellWidget(i int, s string) gowid.IWidget

type ISimpleRowProvider Uses

type ISimpleRowProvider interface {
    GetStyle() StyleOptions

type IWidgetAt Uses

type IWidgetAt interface {
    HorzDivider() gowid.IWidget
    RowToWidget(ws []gowid.IWidget) gowid.IWidget

type IntCompare Uses

type IntCompare struct{}

IntCompare is a unit type that satisfies ICompare, and can be used for numerically comparing ints.

func (IntCompare) Less Uses

func (s IntCompare) Less(i, j string) bool

type LayoutOptions Uses

type LayoutOptions struct {
    Widths []gowid.IWidgetDimension

type ListWithPreferedColumn Uses

type ListWithPreferedColumn struct {
    list.IWidget // so we can use bounded or unbounded lists

ListWithPreferedColumn acts like a list.Widget but also satisfies gowid.IPreferedPosition. The idea is that if the list rows consist of columns, then moving up and down the list should preserve the selected column.

func (*ListWithPreferedColumn) GetPreferedPosition Uses

func (l *ListWithPreferedColumn) GetPreferedPosition() gwutil.IntOption

func (*ListWithPreferedColumn) SetPreferedPosition Uses

func (l *ListWithPreferedColumn) SetPreferedPosition(col int, app gowid.IApp)

func (*ListWithPreferedColumn) String Uses

func (w *ListWithPreferedColumn) String() string

func (*ListWithPreferedColumn) SubWidget Uses

func (l *ListWithPreferedColumn) SubWidget() gowid.IWidget

type NoFocus Uses

type NoFocus struct{}

func (NoFocus) Error Uses

func (n NoFocus) Error() string

type Options Uses

type Options struct {
    CacheSize int

type Position Uses

type Position int

func (Position) Equal Uses

func (t Position) Equal(pos list.IWalkerPosition) bool

func (Position) GreaterThan Uses

func (t Position) GreaterThan(pos list.IWalkerPosition) bool

func (Position) ToInt Uses

func (t Position) ToInt() int

type RenderWithUnitsMax Uses

type RenderWithUnitsMax struct {

type RowId Uses

type RowId int

RowId is used to uniquely identify a row. The idea here is that a table row can move in the order of rows rendered, if the table is sorted, but we would like to preserve the ability to cache the row's widgets (e.g. the selected column in the row). So a client of an ITable should first look up a RowId given an actual row to be rendered (1st, 2nd, etc). Then with the RowId, the client asks for the RowWidgets. Clients of ITable can then cache the rendered row using the RowId as a lookup field. Even if that row moves around in the order rendered, it can be found in the cache.

type SimpleModel Uses

type SimpleModel struct {
    Headers      []string
    Data         [][]string
    Comparators  []ICompare
    SortOrder    []int // table row order as displayed -> table row identifier (RowId)
    InvSortOrder []int // table row identifier (RowId) -> table row order as displayed
    Style        StyleOptions
    Layout       LayoutOptions

SimpleModel implements table.IModel and can be used as a simple model for table.IWidget. Fill in the headers, the data; initialize the SortOrder array and provide any styling needed. The resulting struct can then be rendered as a table.

func NewCsvModel Uses

func NewCsvModel(csvFile io.Reader, firstLineIsHeaders bool, opts ...SimpleOptions) *SimpleModel

NewCsvModel returns a SimpleTable built from CSV data in the supplied reader. SimpleTable implements IModel, and so can be used as a source for table.IWidget.

func NewSimpleModel Uses

func NewSimpleModel(headers []string, res [][]string, opts ...SimpleOptions) *SimpleModel

NewSimpleModel returns a SimpleTable built from caller-supplied header data and table data. SimpleTable implements IModel, and so can be used as a source for table.IWidget.

func (*SimpleModel) CellWidget Uses

func (c *SimpleModel) CellWidget(i int, s string) gowid.IWidget

func (*SimpleModel) CellWidgets Uses

func (c *SimpleModel) CellWidgets(rowid RowId) []gowid.IWidget

func (*SimpleModel) Columns Uses

func (c *SimpleModel) Columns() int

func (*SimpleModel) GetData Uses

func (c *SimpleModel) GetData() [][]string

func (*SimpleModel) GetStyle Uses

func (c *SimpleModel) GetStyle() StyleOptions

func (*SimpleModel) HeaderSeparator Uses

func (c *SimpleModel) HeaderSeparator() gowid.IWidget

func (*SimpleModel) HeaderWidget Uses

func (c *SimpleModel) HeaderWidget(ws []gowid.IWidget, focus int) gowid.IWidget

func (*SimpleModel) HeaderWidgets Uses

func (c *SimpleModel) HeaderWidgets() []gowid.IWidget

func (*SimpleModel) HorizontalSeparator Uses

func (c *SimpleModel) HorizontalSeparator() gowid.IWidget

func (*SimpleModel) IdentifierToRow Uses

func (c *SimpleModel) IdentifierToRow(rowid RowId) (int, bool)

func (*SimpleModel) RowIdentifier Uses

func (c *SimpleModel) RowIdentifier(row int) (RowId, bool)

func (*SimpleModel) Rows Uses

func (c *SimpleModel) Rows() int

func (*SimpleModel) VerticalSeparator Uses

func (c *SimpleModel) VerticalSeparator() gowid.IWidget

func (*SimpleModel) Widths Uses

func (c *SimpleModel) Widths() []gowid.IWidgetDimension

type SimpleOptions Uses

type SimpleOptions struct {
    NoDefaultSorters bool
    Comparators      []ICompare
    Style            StyleOptions
    Layout           LayoutOptions

type SimpleTableByColumn Uses

type SimpleTableByColumn struct {
    Column int

SimpleTableByColumn is a SimpleTable with a selected column; it's intended to be sortable, with the values in the selected column being those compared.

func (*SimpleTableByColumn) Len Uses

func (m *SimpleTableByColumn) Len() int

func (*SimpleTableByColumn) Less Uses

func (m *SimpleTableByColumn) Less(i, j int) bool

func (*SimpleTableByColumn) Swap Uses

func (m *SimpleTableByColumn) Swap(i, j int)

type StringCompare Uses

type StringCompare struct{}

StringCompare is a unit type that satisfies ICompare, and can be used for lexicographically comparing strings.

func (StringCompare) Less Uses

func (s StringCompare) Less(i, j string) bool

type StyleOptions Uses

type StyleOptions struct {
    VerticalSeparator   gowid.IWidget
    HorizontalSeparator gowid.IWidget
    TableSeparator      gowid.IWidget
    HeaderStyleProvided bool
    HeaderStyleNoFocus  gowid.ICellStyler
    HeaderStyleSelected gowid.ICellStyler
    HeaderStyleFocus    gowid.ICellStyler
    CellStyleProvided   bool
    CellStyleNoFocus    gowid.ICellStyler
    CellStyleSelected   gowid.ICellStyler
    CellStyleFocus      gowid.ICellStyler

type Widget Uses

type Widget struct {
    // contains filtered or unexported fields

Widget wraps a widget and aligns it vertically according to the supplied arguments. The wrapped widget can be aligned to the top, bottom or middle, and can be provided with a specific height in #lines.

func New Uses

func New(model IModel, opts ...Options) *Widget

func (*Widget) At Uses

func (t *Widget) At(pos list.IWalkerPosition) gowid.IWidget


func (*Widget) AtRow Uses

func (t *Widget) AtRow(pos int) gowid.IWidget

WidgetAt is used by the type that satisfies list.IWalker - therefore it provides a row for each line of the list. That means that if the table has dividers, it provides them too.

func (*Widget) Cache Uses

func (w *Widget) Cache() *lru.Cache

func (*Widget) CalculateOnScreen Uses

func (w *Widget) CalculateOnScreen(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) (int, int, int, error)

func (*Widget) CurrentRow Uses

func (w *Widget) CurrentRow() int

func (*Widget) Down Uses

func (w *Widget) Down(lines int, size gowid.IRenderSize, app gowid.IApp)

func (*Widget) DownPage Uses

func (w *Widget) DownPage(num int, size gowid.IRenderSize, app gowid.IApp)

func (*Widget) Focus Uses

func (t *Widget) Focus() list.IWalkerPosition


func (*Widget) FocusXY Uses

func (t *Widget) FocusXY() (Coords, error)

FocusXY returns the coordinates of the focus widget in the table, potentially including the header if one is configured. This is grungy and needs to account for the cell separators in its arithmetic.

func (*Widget) GoToBottom Uses

func (t *Widget) GoToBottom(app gowid.IApp) bool

func (*Widget) GoToMiddle Uses

func (t *Widget) GoToMiddle(app gowid.IApp)

func (*Widget) HorzDivider Uses

func (w *Widget) HorzDivider() gowid.IWidget

func (*Widget) Lower Uses

func (w *Widget) Lower() *ListWithPreferedColumn

func (*Widget) Model Uses

func (w *Widget) Model() IModel

func (*Widget) Next Uses

func (t *Widget) Next(ipos list.IWalkerPosition) list.IWalkerPosition

In order to implement list.IWalker list.IWalker

func (*Widget) Previous Uses

func (t *Widget) Previous(ipos list.IWalkerPosition) list.IWalkerPosition

In order to implement list.IWalker list.IWalker

func (*Widget) Render Uses

func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas

func (*Widget) RenderSize Uses

func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox

func (*Widget) RowToWidget Uses

func (t *Widget) RowToWidget(ws []gowid.IWidget) gowid.IWidget

func (*Widget) SetCurrentRow Uses

func (w *Widget) SetCurrentRow(p Position)

func (*Widget) SetFocus Uses

func (t *Widget) SetFocus(pos list.IWalkerPosition, app gowid.IApp)

In order to implement list.IWalker list.IWalker

func (*Widget) SetFocusOnData Uses

func (w *Widget) SetFocusOnData(app gowid.IApp) bool

SetFocusOnData returns true if there is data to focus on

func (*Widget) SetFocusOnHeader Uses

func (w *Widget) SetFocusOnHeader(app gowid.IApp)

func (*Widget) SetFocusXY Uses

func (t *Widget) SetFocusXY(app gowid.IApp, xy Coords)

func (*Widget) SetLower Uses

func (w *Widget) SetLower(l *ListWithPreferedColumn)

func (*Widget) SetModel Uses

func (w *Widget) SetModel(model IModel, app gowid.IApp)

func (*Widget) String Uses

func (w *Widget) String() string

func (*Widget) TableDivider Uses

func (w *Widget) TableDivider() gowid.IContainerWidget

func (*Widget) Up Uses

func (w *Widget) Up(lines int, size gowid.IRenderSize, app gowid.IApp)

func (*Widget) UpPage Uses

func (w *Widget) UpPage(num int, size gowid.IRenderSize, app gowid.IApp)

func (*Widget) UserInput Uses

func (w *Widget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool

func (*Widget) VertDivider Uses

func (w *Widget) VertDivider() gowid.IContainerWidget

Package table imports 20 packages (graph) and is imported by 6 packages. Updated 2020-02-12. Refresh now. Tools for package owners.