table

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 21 Imported by: 12

Documentation

Overview

A simple implementation of a CSV table widget.

Package table provides a widget that renders tabular output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Focus

func Focus(t IFocus) list.IWalkerPosition

list.IWalker

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

func WidgetAt

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

Provide the pos'th "row" widget

Types

type BoundedWidget

type BoundedWidget struct {
	*Widget
}

func (*BoundedWidget) BoundedWalker added in v1.1.0

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

func (*BoundedWidget) First

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

func (*BoundedWidget) Last

func (*BoundedWidget) Length

func (w *BoundedWidget) Length() int

func (*BoundedWidget) Pos added in v1.1.0

func (w *BoundedWidget) Pos() int

func (*BoundedWidget) SetPos added in v1.2.0

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

type Coords

type Coords struct {
	Column int
	Row    int
}

func (Coords) String

func (c Coords) String() string

type DateTimeCompare added in v1.3.0

type DateTimeCompare struct{}

DateTimeCompare is a unit type that satisfies ICompare, and can be used for numerically comparing date/time values.

func (DateTimeCompare) Less added in v1.3.0

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

type IBoundedModel interface {
	IModel
	Rows() int
}

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

type ICompare

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

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

type IGoToBottom added in v1.1.0

type IGoToBottom interface {
	GoToBottom(app gowid.IApp)
}

type IGoToMiddle added in v1.1.0

type IGoToMiddle interface {
	GoToMiddle(app gowid.IApp)
}

type IGoToTop added in v1.2.0

type IGoToTop interface {
	GoToTop(app gowid.IApp)
}

type IInvertible added in v1.1.0

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

type IMakeHeader

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

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 ISetFocus

type ISetFocus interface {
	SetCurrentRow(pos Position)
}

type ISetPos added in v1.2.0

type ISetPos interface {
	Length() int
	SetPos(pos list.IBoundedWalkerPosition, app gowid.IApp)
}

type ISimpleDataProvider

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

type ISimpleRowProvider

type ISimpleRowProvider interface {
	GetStyle() StyleOptions
}

type IWidgetAt

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

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

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

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 NoFocus

type NoFocus struct{}

func (NoFocus) Error

func (n NoFocus) Error() string

type Options

type Options struct {
	CacheSize int
}

type Position

type Position int

func (Position) Equal

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

func (Position) GreaterThan

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

func (Position) ToInt

func (t Position) ToInt() int

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 (c *SimpleModel) HeaderWidget(ws []gowid.IWidget, focus int) gowid.IWidget

func (*SimpleModel) HeaderWidgets

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

func (*SimpleModel) HorizontalSeparator

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

func (*SimpleModel) IdentifierToRow added in v1.1.0

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 New

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

func (*Widget) At

list.IWalker

func (*Widget) AtRow

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

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

func (*Widget) CalculateOnScreen

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

func (*Widget) CurrentRow

func (w *Widget) CurrentRow() int

func (*Widget) Down added in v1.1.0

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

func (*Widget) DownPage added in v1.1.0

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

func (*Widget) Focus

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

list.IWalker

func (*Widget) FocusXY

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 added in v1.1.0

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

func (*Widget) GoToFirst added in v1.2.0

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

func (*Widget) GoToLast added in v1.2.0

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

func (*Widget) GoToMiddle added in v1.1.0

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

func (*Widget) GoToNth added in v1.2.0

func (t *Widget) GoToNth(app gowid.IApp, pos int) bool

func (*Widget) GoToTop added in v1.2.0

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

func (*Widget) HorzDivider

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

func (*Widget) Lower

func (w *Widget) Lower() *ListWithPreferedColumn

func (*Widget) Model

func (w *Widget) Model() IModel

func (*Widget) Next

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

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

func (*Widget) RenderSize

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

func (*Widget) RowToWidget

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

func (*Widget) SetCurrentRow

func (w *Widget) SetCurrentRow(p Position)

func (*Widget) SetFocus

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

In order to implement list.IWalker list.IWalker

func (*Widget) SetFocusOnData added in v1.1.0

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

SetFocusOnData returns true if there is data to focus on

func (*Widget) SetFocusOnHeader added in v1.1.0

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

func (*Widget) SetFocusXY

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

func (*Widget) SetLower

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

func (*Widget) SetModel

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

func (*Widget) String

func (w *Widget) String() string

func (*Widget) TableDivider

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

func (*Widget) Up added in v1.1.0

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

func (*Widget) UpPage added in v1.1.0

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

func (*Widget) UserInput

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

func (*Widget) VertDivider

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

Jump to

Keyboard shortcuts

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