model1

package
v0.0.0-...-2cb8b77 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0, Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ModColor row modified color.
	ModColor tcell.Color

	// AddColor row added color.
	AddColor tcell.Color

	// PendingColor row added color.
	PendingColor tcell.Color

	// ErrColor row err color.
	ErrColor tcell.Color

	// StdColor row default color.
	StdColor tcell.Color

	// HighlightColor row highlight color.
	HighlightColor tcell.Color

	// KillColor row deleted color.
	KillColor tcell.Color

	// CompletedColor row completed color.
	CompletedColor tcell.Color
)

Functions

func DefaultColorer

func DefaultColorer(ns string, h Header, re *RowEvent) tcell.Color

DefaultColorer set the default table row colors.

func GenericHydrate

func GenericHydrate(ns string, table *metav1.Table, rr Rows, re Renderer) error

func Hydrate

func Hydrate(ns string, oo []runtime.Object, rr Rows, re Renderer) error

func IsValid

func IsValid(ns string, h Header, r Row) bool

IsValid returns true if resource is valid, false otherwise.

func Less

func Less(isNumber, isDuration, isCapacity bool, id1, id2, v1, v2 string) bool

Less return true if c1 <= c2.

Types

type ColorerFunc

type ColorerFunc func(ns string, h Header, re *RowEvent) tcell.Color

ColorerFunc represents a resource row colorer.

type DecoratorFunc

type DecoratorFunc func(string) string

DecoratorFunc decorates a string.

type DeltaRow

type DeltaRow []string

DeltaRow represents a collection of row deltas between old and new row.

func NewDeltaRow

func NewDeltaRow(o, n Row, h Header) DeltaRow

NewDeltaRow computes the delta between 2 rows.

func (DeltaRow) Clone

func (d DeltaRow) Clone() DeltaRow

Clone returns a delta copy.

func (DeltaRow) Customize

func (d DeltaRow) Customize(cols []int, out DeltaRow)

Customize returns a subset of deltas.

func (DeltaRow) Diff

func (d DeltaRow) Diff(r DeltaRow, ageCol int) bool

Diff returns true if deltas differ or false otherwise.

func (DeltaRow) IsBlank

func (d DeltaRow) IsBlank() bool

IsBlank asserts a row has no values in it.

func (DeltaRow) Labelize

func (d DeltaRow) Labelize(cols []int, labelCol int) DeltaRow

Labelize returns a new deltaRow based on labels.

type Fields

type Fields []string

Fields represents a collection of row fields.

func (Fields) Clone

func (f Fields) Clone() Fields

Clone returns a copy of the fields.

func (Fields) Customize

func (f Fields) Customize(cols []int, out Fields)

Customize returns a subset of fields.

func (Fields) Diff

func (f Fields) Diff(ff Fields, ageCol int) bool

Diff returns true if fields differ or false otherwise.

type FilterOpts

type FilterOpts struct {
	Toast  bool
	Filter string
	Invert bool
}

type Generic

type Generic interface {
	// SetTable sets up the resource tabular definition.
	SetTable(ns string, table *metav1.Table)

	// Header returns a resource header.
	Header(ns string) Header

	// Render renders the resource.
	Render(o interface{}, ns string, row *Row) error
}

Generic represents a generic resource.

type Header []HeaderColumn

Header represents a table header.

func (Header) Clear

func (h Header) Clear() Header

func (Header) Clone

func (h Header) Clone() Header

Clone duplicates a header.

func (Header) ColumnNames

func (h Header) ColumnNames(wide bool) []string

ColumnNames return header col names

func (Header) Customize

func (h Header) Customize(cols []string, wide bool) Header

Customize builds a header from custom col definitions.

func (Header) Diff

func (h Header) Diff(header Header) bool

Diff returns true if the header changed.

func (Header) Dump

func (h Header) Dump()

Dump for debugging.

func (Header) HasAge

func (h Header) HasAge() bool

HasAge returns true if table has an age column.

func (Header) IndexOf

func (h Header) IndexOf(colName string, includeWide bool) (int, bool)

IndexOf returns the col index or -1 if none.

func (Header) IsCapacityCol

func (h Header) IsCapacityCol(col int) bool

IsCapacityCol checks if given column index represents a capacity.

func (Header) IsMetricsCol

func (h Header) IsMetricsCol(col int) bool

IsMetricsCol checks if given column index represents metrics.

func (Header) IsTimeCol

func (h Header) IsTimeCol(col int) bool

IsTimeCol checks if given column index represents a timestamp.

func (Header) Labelize

func (h Header) Labelize(cols []int, labelCol int, rr *RowEvents) Header

Labelize returns a new Header based on labels.

func (Header) MapIndices

func (h Header) MapIndices(cols []string, wide bool) []int

MapIndices returns a collection of mapped column indices based of the requested columns.

type HeaderColumn

type HeaderColumn struct {
	Name      string
	Align     int
	Decorator DecoratorFunc
	Wide      bool
	MX        bool
	Time      bool
	Capacity  bool
	VS        bool
}

HeaderColumn represent a table header.

func (HeaderColumn) Clone

func (h HeaderColumn) Clone() HeaderColumn

Clone copies a header.

type ReRangeFn

type ReRangeFn func(int, RowEvent) bool

type Renderer

type Renderer interface {
	// IsGeneric identifies a generic handler.
	IsGeneric() bool

	// Render converts raw resources to tabular data.
	Render(o interface{}, ns string, row *Row) error

	// Header returns the resource header.
	Header(ns string) Header

	// ColorerFunc returns a row colorer function.
	ColorerFunc() ColorerFunc
}

Renderer represents a resource renderer.

type ResEvent

type ResEvent int

ResEvent represents a resource event.

const (
	NAValue = "na"

	// EventUnchanged notifies listener resource has not changed.
	EventUnchanged ResEvent = 1 << iota

	// EventAdd notifies listener of a resource was added.
	EventAdd

	// EventUpdate notifies listener of a resource updated.
	EventUpdate

	// EventDelete  notifies listener of a resource was deleted.
	EventDelete

	// EventClear the stack was reset.
	EventClear
)

type Row

type Row struct {
	ID     string
	Fields Fields
}

Row represents a collection of columns.

func NewRow

func NewRow(size int) Row

NewRow returns a new row with initialized fields.

func (Row) Clone

func (r Row) Clone() Row

Clone copies a row.

func (Row) Customize

func (r Row) Customize(cols []int) Row

Customize returns a row subset based on given col indices.

func (Row) Diff

func (r Row) Diff(ro Row, ageCol int) bool

Diff returns true if row differ or false otherwise.

func (Row) Labelize

func (r Row) Labelize(cols []int, labelCol int, labels []string) Row

Labelize returns a new row based on labels.

func (Row) Len

func (r Row) Len() int

Len returns the length of the row.

type RowEvent

type RowEvent struct {
	Kind   ResEvent
	Row    Row
	Deltas DeltaRow
}

RowEvent tracks resource instance events.

func NewRowEvent

func NewRowEvent(kind ResEvent, row Row) RowEvent

NewRowEvent returns a new row event.

func NewRowEventWithDeltas

func NewRowEventWithDeltas(row Row, delta DeltaRow) RowEvent

NewRowEventWithDeltas returns a new row event with deltas.

func (RowEvent) Clone

func (r RowEvent) Clone() RowEvent

Clone returns a row event deep copy.

func (RowEvent) Customize

func (r RowEvent) Customize(cols []int) RowEvent

Customize returns a new subset based on the given column indices.

func (RowEvent) Diff

func (r RowEvent) Diff(re RowEvent, ageCol int) bool

Diff returns true if the row changed.

func (RowEvent) ExtractHeaderLabels

func (r RowEvent) ExtractHeaderLabels(labelCol int) []string

ExtractHeaderLabels extract collection of fields into header.

func (RowEvent) Labelize

func (r RowEvent) Labelize(cols []int, labelCol int, labels []string) RowEvent

Labelize returns a new row event based on labels.

type RowEventSorter

type RowEventSorter struct {
	Events     *RowEvents
	Index      int
	NS         string
	IsNumber   bool
	IsDuration bool
	IsCapacity bool
	Asc        bool
}

RowEventSorter sorts row events by a given colon.

func (RowEventSorter) Len

func (r RowEventSorter) Len() int

func (RowEventSorter) Less

func (r RowEventSorter) Less(i, j int) bool

func (RowEventSorter) Swap

func (r RowEventSorter) Swap(i, j int)

type RowEvents

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

RowEvents a collection of row events.

func NewRowEvents

func NewRowEvents(size int) *RowEvents

func NewRowEventsWithEvts

func NewRowEventsWithEvts(ee ...RowEvent) *RowEvents

func (*RowEvents) Add

func (r *RowEvents) Add(re RowEvent)

func (*RowEvents) At

func (r *RowEvents) At(i int) (RowEvent, bool)

func (*RowEvents) Clear

func (r *RowEvents) Clear()

Clear delete all row events.

func (*RowEvents) Clone

func (r *RowEvents) Clone() *RowEvents

Clone returns a deep copy.

func (*RowEvents) Customize

func (r *RowEvents) Customize(cols []int) *RowEvents

Customize returns custom row events based on columns layout.

func (*RowEvents) Delete

func (r *RowEvents) Delete(fqn string) error

Delete removes an element by id.

func (*RowEvents) Diff

func (r *RowEvents) Diff(re *RowEvents, ageCol int) bool

Diff returns true if the event changed.

func (*RowEvents) Empty

func (r *RowEvents) Empty() bool

func (*RowEvents) ExtractHeaderLabels

func (r *RowEvents) ExtractHeaderLabels(labelCol int) []string

ExtractHeaderLabels extract header labels.

func (*RowEvents) FindIndex

func (r *RowEvents) FindIndex(id string) (int, bool)

FindIndex locates a row index by id. Returns false is not found.

func (*RowEvents) Get

func (r *RowEvents) Get(id string) (RowEvent, bool)

func (*RowEvents) Labelize

func (r *RowEvents) Labelize(cols []int, labelCol int, labels []string) *RowEvents

Labelize converts labels into a row event.

func (*RowEvents) Len

func (r *RowEvents) Len() int

func (*RowEvents) Range

func (r *RowEvents) Range(f ReRangeFn)

func (*RowEvents) Set

func (r *RowEvents) Set(i int, re RowEvent)

func (*RowEvents) Sort

func (r *RowEvents) Sort(ns string, sortCol int, isDuration, numCol, isCapacity, asc bool)

Sort rows based on column index and order.

func (*RowEvents) Upsert

func (r *RowEvents) Upsert(re RowEvent)

Upsert add or update a row if it exists.

type RowSorter

type RowSorter struct {
	Rows       Rows
	Index      int
	IsNumber   bool
	IsDuration bool
	IsCapacity bool
	Asc        bool
}

RowSorter sorts rows.

func (RowSorter) Len

func (s RowSorter) Len() int

func (RowSorter) Less

func (s RowSorter) Less(i, j int) bool

func (RowSorter) Swap

func (s RowSorter) Swap(i, j int)

type Rows

type Rows []Row

Rows represents a collection of rows.

func (Rows) Delete

func (rr Rows) Delete(id string) Rows

Delete removes an element by id.

func (Rows) Find

func (rr Rows) Find(id string) (int, bool)

Find locates a row by id. Returns false is not found.

func (Rows) Sort

func (rr Rows) Sort(col int, asc, isNum, isDur, isCapacity bool)

Sort rows based on column index and order.

func (Rows) Upsert

func (rr Rows) Upsert(r Row) Rows

Upsert adds a new item.

type SortColumn

type SortColumn struct {
	Name string
	ASC  bool
}

SortColumn represents a sortable column.

type SortFn

type SortFn func(rows Rows, sortCol SortColumn)

SortFn represent a function that can sort columnar data.

type TableData

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

TableData tracks a K8s resource for tabular display.

func NewTableData

func NewTableData(gvr client.GVR) *TableData

NewTableData returns a new table.

func NewTableDataFromTable

func NewTableDataFromTable(td *TableData) *TableData

func NewTableDataFull

func NewTableDataFull(gvr client.GVR, ns string, h Header, re *RowEvents) *TableData

func NewTableDataWithRows

func NewTableDataWithRows(gvr client.GVR, h Header, re *RowEvents) *TableData

func (*TableData) AddRow

func (t *TableData) AddRow(re RowEvent)

func (*TableData) Clear

func (t *TableData) Clear()

Clear clears out the entire table.

func (*TableData) Clone

func (t *TableData) Clone() *TableData

Clone returns a copy of the table.

func (*TableData) ColumnNames

func (t *TableData) ColumnNames(w bool) []string

func (*TableData) Customize

func (t *TableData) Customize(vs *config.ViewSetting, sc SortColumn, manual, wide bool) (*TableData, SortColumn)

Customize returns a new model with customized column layout.

func (*TableData) Delete

func (t *TableData) Delete(newKeys map[string]struct{})

Delete removes items in cache that are no longer valid.

func (*TableData) Diff

func (t *TableData) Diff(t2 *TableData) bool

Diff checks if two tables are equal.

func (*TableData) Empty

func (t *TableData) Empty() bool

Empty checks if there are no entries.

func (*TableData) Filter

func (t *TableData) Filter(f FilterOpts) *TableData

func (*TableData) FindRow

func (t *TableData) FindRow(id string) (RowEvent, bool)

func (*TableData) GetHeader

func (t *TableData) GetHeader() Header

GetHeader returns table header.

func (*TableData) GetNamespace

func (t *TableData) GetNamespace() string

func (*TableData) GetRowEvents

func (t *TableData) GetRowEvents() *RowEvents

func (*TableData) HeadCol

func (t *TableData) HeadCol(n string, w bool) (HeaderColumn, int)

func (*TableData) Header

func (t *TableData) Header() Header

func (*TableData) HeaderCount

func (t *TableData) HeaderCount() int

HeaderCount returns the number of header cols.

func (*TableData) IndexOfHeader

func (t *TableData) IndexOfHeader(h string) (int, bool)

IndexOfHeader return the index of the header.

func (*TableData) Labelize

func (t *TableData) Labelize(labels []string) *TableData

Labelize prints out specific label columns.

func (*TableData) Reconcile

func (t *TableData) Reconcile(ctx context.Context, r Renderer, oo []runtime.Object) error

func (*TableData) Reset

func (t *TableData) Reset(ns string)

func (*TableData) RowAt

func (t *TableData) RowAt(idx int) (RowEvent, bool)

func (*TableData) RowCount

func (t *TableData) RowCount() int

RowCount returns the number of rows.

func (*TableData) RowsRange

func (t *TableData) RowsRange(f ReRangeFn)

func (*TableData) SetHeader

func (t *TableData) SetHeader(ns string, h Header)

SetHeader sets table header.

func (*TableData) SetRow

func (t *TableData) SetRow(idx int, re RowEvent)

func (*TableData) SetRowEvents

func (t *TableData) SetRowEvents(re *RowEvents)

func (*TableData) Sort

func (t *TableData) Sort(sc SortColumn)

func (*TableData) Update

func (t *TableData) Update(rows Rows)

Update computes row deltas and update the table data.

Jump to

Keyboard shortcuts

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