Documentation ¶
Overview ¶
A simple implementation of a CSV table widget.
Package table provides a widget that renders tabular output.
Index ¶
- func Focus(t IFocus) list.IWalkerPosition
- func RowToWidget(t IRowToWidget, ws []gowid.IWidget) gowid.IWidget
- func SetFocus(t ISetFocus, pos list.IWalkerPosition)
- func SimpleCellWidget(c ISimpleRowProvider, i int, s string) gowid.IWidget
- func SimpleCellWidgets(c ISimpleDataProvider, row2 RowId) []gowid.IWidget
- func WidgetAt(t IWidgetAt, pos int) gowid.IWidget
- type BoundedWidget
- func (w *BoundedWidget) BoundedWalker() list.IBoundedWalker
- func (w *BoundedWidget) First() list.IWalkerPosition
- func (w *BoundedWidget) Last() list.IWalkerPosition
- func (w *BoundedWidget) Length() int
- func (w *BoundedWidget) Pos() int
- func (w *BoundedWidget) SetPos(pos list.IBoundedWalkerPosition, app gowid.IApp)
- type Coords
- type DateTimeCompare
- type FloatCompare
- type IBoundedModel
- type ICompare
- type IFocus
- type IGoToBottom
- type IGoToMiddle
- type IGoToTop
- type IInvertible
- type IMakeHeader
- type IModel
- type IRowToWidget
- type ISetFocus
- type ISetPos
- type ISimpleDataProvider
- type ISimpleRowProvider
- type IWidgetAt
- type IntCompare
- type LayoutOptions
- type ListWithPreferedColumn
- type NoFocus
- type Options
- type Position
- type RenderWithUnitsMax
- type RowId
- type SimpleModel
- func (c *SimpleModel) CellWidget(i int, s string) gowid.IWidget
- func (c *SimpleModel) CellWidgets(rowid RowId) []gowid.IWidget
- func (c *SimpleModel) Columns() int
- func (c *SimpleModel) GetData() [][]string
- func (c *SimpleModel) GetStyle() StyleOptions
- func (c *SimpleModel) HeaderSeparator() gowid.IWidget
- func (c *SimpleModel) HeaderWidget(ws []gowid.IWidget, focus int) gowid.IWidget
- func (c *SimpleModel) HeaderWidgets() []gowid.IWidget
- func (c *SimpleModel) HorizontalSeparator() gowid.IWidget
- func (c *SimpleModel) IdentifierToRow(rowid RowId) (int, bool)
- func (c *SimpleModel) RowIdentifier(row int) (RowId, bool)
- func (c *SimpleModel) Rows() int
- func (c *SimpleModel) VerticalSeparator() gowid.IWidget
- func (c *SimpleModel) Widths() []gowid.IWidgetDimension
- type SimpleOptions
- type SimpleTableByColumn
- type StringCompare
- type StyleOptions
- type Widget
- func (t *Widget) At(pos list.IWalkerPosition) gowid.IWidget
- func (t *Widget) AtRow(pos int) gowid.IWidget
- func (w *Widget) Cache() *lru.Cache
- func (w *Widget) CalculateOnScreen(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) (int, int, int, error)
- func (w *Widget) CurrentRow() int
- func (w *Widget) Down(lines int, size gowid.IRenderSize, app gowid.IApp)
- func (w *Widget) DownPage(num int, size gowid.IRenderSize, app gowid.IApp)
- func (t *Widget) Focus() list.IWalkerPosition
- func (t *Widget) FocusXY() (Coords, error)
- func (t *Widget) GoToBottom(app gowid.IApp) bool
- func (t *Widget) GoToFirst(app gowid.IApp) bool
- func (t *Widget) GoToLast(app gowid.IApp) bool
- func (t *Widget) GoToMiddle(app gowid.IApp)
- func (t *Widget) GoToNth(app gowid.IApp, pos int) bool
- func (t *Widget) GoToTop(app gowid.IApp) bool
- func (w *Widget) HorzDivider() gowid.IWidget
- func (w *Widget) Lower() *ListWithPreferedColumn
- func (w *Widget) Model() IModel
- func (t *Widget) Next(ipos list.IWalkerPosition) list.IWalkerPosition
- func (t *Widget) Previous(ipos list.IWalkerPosition) list.IWalkerPosition
- func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
- func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
- func (t *Widget) RowToWidget(ws []gowid.IWidget) gowid.IWidget
- func (w *Widget) SetCurrentRow(p Position)
- func (t *Widget) SetFocus(pos list.IWalkerPosition, app gowid.IApp)
- func (w *Widget) SetFocusOnData(app gowid.IApp) bool
- func (w *Widget) SetFocusOnHeader(app gowid.IApp)
- func (t *Widget) SetFocusXY(app gowid.IApp, xy Coords)
- func (w *Widget) SetLower(l *ListWithPreferedColumn)
- func (w *Widget) SetModel(model IModel, app gowid.IApp)
- func (w *Widget) String() string
- func (w *Widget) TableDivider() gowid.IContainerWidget
- func (w *Widget) Up(lines int, size gowid.IRenderSize, app gowid.IApp)
- func (w *Widget) UpPage(num int, size gowid.IRenderSize, app gowid.IApp)
- func (w *Widget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool
- func (w *Widget) VertDivider() gowid.IContainerWidget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RowToWidget ¶
func RowToWidget(t IRowToWidget, ws []gowid.IWidget) gowid.IWidget
func SetFocus ¶
func SetFocus(t ISetFocus, pos list.IWalkerPosition)
In order to implement list.IWalker
func SimpleCellWidget ¶
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 ¶
func SimpleCellWidgets(c ISimpleDataProvider, row2 RowId) []gowid.IWidget
Types ¶
type BoundedWidget ¶
type BoundedWidget struct {
*Widget
}
func (*BoundedWidget) BoundedWalker ¶
func (w *BoundedWidget) BoundedWalker() list.IBoundedWalker
func (*BoundedWidget) First ¶
func (w *BoundedWidget) First() list.IWalkerPosition
func (*BoundedWidget) Last ¶
func (w *BoundedWidget) Last() list.IWalkerPosition
func (*BoundedWidget) Length ¶
func (w *BoundedWidget) Length() int
func (*BoundedWidget) Pos ¶
func (w *BoundedWidget) Pos() int
func (*BoundedWidget) SetPos ¶
func (w *BoundedWidget) SetPos(pos list.IBoundedWalkerPosition, app gowid.IApp)
type DateTimeCompare ¶
type DateTimeCompare struct{}
DateTimeCompare is a unit type that satisfies ICompare, and can be used for numerically comparing date/time values.
func (DateTimeCompare) Less ¶
func (s DateTimeCompare) Less(i, j string) bool
type FloatCompare ¶
type FloatCompare struct{}
FloatCompare is a unit type that satisfies ICompare, and can be used for numerically comparing float64 values.
func (FloatCompare) Less ¶
func (s FloatCompare) Less(i, j string) bool
type IBoundedModel ¶
IBoundedTable implements ITable and can also provide the total number of rows in the table.
type IGoToBottom ¶
type IGoToMiddle ¶
type IInvertible ¶
type IModel ¶
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 ¶
type IRowToWidget interface { VertDivider() gowid.IContainerWidget Model() IModel Cache() *lru.Cache }
type ISetPos ¶
type ISetPos interface { Length() int SetPos(pos list.IBoundedWalkerPosition, app gowid.IApp) }
type ISimpleDataProvider ¶
type ISimpleRowProvider ¶
type ISimpleRowProvider interface {
GetStyle() StyleOptions
}
type IntCompare ¶
type IntCompare struct{}
IntCompare is a unit type that satisfies ICompare, and can be used for numerically comparing ints.
func (IntCompare) Less ¶
func (s IntCompare) Less(i, j string) bool
type LayoutOptions ¶
type LayoutOptions struct {
Widths []gowid.IWidgetDimension
}
type ListWithPreferedColumn ¶
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 ¶
func (l *ListWithPreferedColumn) GetPreferedPosition() gwutil.IntOption
func (*ListWithPreferedColumn) SetPreferedPosition ¶
func (l *ListWithPreferedColumn) SetPreferedPosition(col int, app gowid.IApp)
func (*ListWithPreferedColumn) String ¶
func (w *ListWithPreferedColumn) String() string
func (*ListWithPreferedColumn) SubWidget ¶
func (l *ListWithPreferedColumn) SubWidget() gowid.IWidget
type Position ¶
type Position int
func (Position) GreaterThan ¶
func (t Position) GreaterThan(pos list.IWalkerPosition) bool
type RenderWithUnitsMax ¶
type RenderWithUnitsMax struct { gowid.RenderWithUnits gowid.RenderMax }
type RowId ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (c *SimpleModel) CellWidget(i int, s string) gowid.IWidget
func (*SimpleModel) CellWidgets ¶
func (c *SimpleModel) CellWidgets(rowid RowId) []gowid.IWidget
func (*SimpleModel) Columns ¶
func (c *SimpleModel) Columns() int
func (*SimpleModel) GetData ¶
func (c *SimpleModel) GetData() [][]string
func (*SimpleModel) GetStyle ¶
func (c *SimpleModel) GetStyle() StyleOptions
func (*SimpleModel) HeaderSeparator ¶
func (c *SimpleModel) HeaderSeparator() gowid.IWidget
func (*SimpleModel) HeaderWidget ¶
func (*SimpleModel) HeaderWidgets ¶
func (c *SimpleModel) HeaderWidgets() []gowid.IWidget
func (*SimpleModel) HorizontalSeparator ¶
func (c *SimpleModel) HorizontalSeparator() gowid.IWidget
func (*SimpleModel) IdentifierToRow ¶
func (c *SimpleModel) IdentifierToRow(rowid RowId) (int, bool)
func (*SimpleModel) RowIdentifier ¶
func (c *SimpleModel) RowIdentifier(row int) (RowId, bool)
func (*SimpleModel) Rows ¶
func (c *SimpleModel) Rows() int
func (*SimpleModel) VerticalSeparator ¶
func (c *SimpleModel) VerticalSeparator() gowid.IWidget
func (*SimpleModel) Widths ¶
func (c *SimpleModel) Widths() []gowid.IWidgetDimension
type SimpleOptions ¶
type SimpleOptions struct { NoDefaultSorters bool Comparators []ICompare Style StyleOptions Layout LayoutOptions }
type SimpleTableByColumn ¶
type SimpleTableByColumn struct { *SimpleModel 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 ¶
func (m *SimpleTableByColumn) Len() int
func (*SimpleTableByColumn) Less ¶
func (m *SimpleTableByColumn) Less(i, j int) bool
func (*SimpleTableByColumn) Swap ¶
func (m *SimpleTableByColumn) Swap(i, j int)
type StringCompare ¶
type StringCompare struct{}
StringCompare is a unit type that satisfies ICompare, and can be used for lexicographically comparing strings.
func (StringCompare) Less ¶
func (s StringCompare) Less(i, j string) bool
type StyleOptions ¶
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 ¶
type Widget struct { *gowid.Callbacks gowid.FocusCallbacks gowid.IsSelectable // 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 (*Widget) AtRow ¶
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) CalculateOnScreen ¶
func (*Widget) CurrentRow ¶
func (*Widget) FocusXY ¶
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) GoToMiddle ¶
func (*Widget) HorzDivider ¶
func (*Widget) Lower ¶
func (w *Widget) Lower() *ListWithPreferedColumn
func (*Widget) Next ¶
func (t *Widget) Next(ipos list.IWalkerPosition) list.IWalkerPosition
In order to implement list.IWalker list.IWalker
func (*Widget) Previous ¶
func (t *Widget) Previous(ipos list.IWalkerPosition) list.IWalkerPosition
In order to implement list.IWalker list.IWalker
func (*Widget) RenderSize ¶
func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
func (*Widget) SetCurrentRow ¶
func (*Widget) SetFocus ¶
func (t *Widget) SetFocus(pos list.IWalkerPosition, app gowid.IApp)
In order to implement list.IWalker list.IWalker
func (*Widget) SetFocusOnData ¶
SetFocusOnData returns true if there is data to focus on
func (*Widget) SetFocusOnHeader ¶
func (*Widget) SetLower ¶
func (w *Widget) SetLower(l *ListWithPreferedColumn)
func (*Widget) TableDivider ¶
func (w *Widget) TableDivider() gowid.IContainerWidget
func (*Widget) VertDivider ¶
func (w *Widget) VertDivider() gowid.IContainerWidget