render

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Terminating represents a pod terminating status.
	Terminating = "Terminating"

	// Running represents a pod running status.
	Running = "RUNNING"

	// Initialized represents a pod initialized status.
	Initialized = "Initialized"

	// Completed represents a pod completed status.
	Completed = "Completed"

	// ContainerCreating represents a pod container status.
	ContainerCreating = "ContainerCreating"

	// PodInitializing represents a pod initializing status.
	PodInitializing = "PodInitializing"

	// Pending represents a pod pending status.
	Pending = "Pending"

	// Blank represents no value.
	Blank = ""

	EXCEPTION = "EXCEPTION"
	OPEN      = "OPEN"
	CLOSED    = "CLOSED"
)
View Source
const (
	// MissingValue indicates an unset value.
	MissingValue = "<none>"

	// NAValue indicates a value that does not pertain.
	NAValue = "n/a"

	// UnknownValue represents an unknown.
	UnknownValue = "<unknown>"

	// UnsetValue represent an unset value.
	UnsetValue = ""

	// ZeroValue represents a zero value.
	ZeroValue = "0"
)
View Source
const (
	// NonResource represents a custom resource.
	NonResource = "*"
)

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
)
View Source
var AgeDecorator = func(a string) string {
	return toAgeHuman(a)
}

AgeDecorator represents a timestamped as human column.

Functions

func AsPerc

func AsPerc(p string) string

AsPerc prints a number as percentage with parens.

func AsThousands

func AsThousands(n int64) string

AsThousands prints a number with thousand separator.

func DefaultColorer

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

DefaultColorer set the default table row colors.

func Happy

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

Happy returns true if resource is happy, false otherwise.

func IntToStr

func IntToStr(p int) string

IntToStr converts an int to a string.

func Less

func Less(asc, isNumber, isDuration bool, c1, c2 string) bool

Less return true if c1 < c2.

func Pad

func Pad(s string, width int) string

Pad a string up to the given length or truncates if greater than length.

func PrintPerc

func PrintPerc(p int) string

PrintPerc prints a number as percentage.

func Truncate

func Truncate(str string, width int) string

Truncate a string to the given l and suffix ellipsis if needed.

Types

type Base

type Base struct{}

func (Base) ColorerFunc

func (Base) ColorerFunc() ColorerFunc

ColorerFunc colors a resource row.

func (Base) Happy

func (Base) Happy(_ string, _ Row) bool

Happy returns true if resource is happy, false otherwise.

func (Base) IsGeneric

func (Base) IsGeneric() bool

IsGeneric identifies a generic handler.

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 Header []HeaderColumn

Header represents a table header.

func (Header) Clone

func (h Header) Clone() Header

Clone duplicates a header.

func (Header) Columns

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

Columns return header as a collection of strings.

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

func (h Header) HasST() bool

HasST returns true if table has an START-TIME column.

func (Header) HasUT

func (h Header) HasUT() bool

HasUT returns true if table has an UPDATE-TIME column.

func (Header) IndexOf

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

IndexOf returns the col index or -1 if none.

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.

func (Header) ValidColIndex

func (h Header) ValidColIndex() int

ValidColIndex returns the valid col index or -1 if none.

type HeaderColumn

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

HeaderColumn represent a table header.

func (HeaderColumn) Clone

func (h HeaderColumn) Clone() HeaderColumn

Clone copies a header.

type IdSorter

type IdSorter struct {
	Ids    []string
	Events RowEvents
}

IdSorter sorts row events by a given id.

func (IdSorter) Len

func (s IdSorter) Len() int

func (IdSorter) Less

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

func (IdSorter) Swap

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

type Namespace

type Namespace struct {
	Base
}

Namespace renders a K8s Namespace to screen.

func (Namespace) ColorerFunc

func (n Namespace) ColorerFunc() ColorerFunc

ColorerFunc colors a resource row.

func (Namespace) Header

func (Namespace) Header(string) Header

Header returns a header rbw.

func (Namespace) Render

func (n Namespace) Render(o interface{}, _ string, rows *Rows) error

Render renders a K8s resource to screen.

type Process

type Process struct {
	Base
}

Process renders a K8s Pod to screen.

func (Process) ColorerFunc

func (p Process) ColorerFunc() ColorerFunc

ColorerFunc colors a resource row.

func (Process) Header

func (Process) Header(ns string) Header

Header returns a header row.

func (Process) Render

func (p Process) Render(o interface{}, ns string, rows *Rows) error

Render renders a K8s resource to screen.

type ResEvent

type ResEvent int

ResEvent represents a resource event.

const (
	// 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
	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 []RowEvent

RowEvents a collection of row events.

func (RowEvents) Clear

func (r RowEvents) Clear() RowEvents

Clear delete all row events.

func (RowEvents) Clone

func (r RowEvents) Clone() RowEvents

Clone returns a rowevents 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(id string) RowEvents

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

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

Labelize converts labels into a row event.

func (RowEvents) Sort

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

Sort rows based on column index and order.

func (RowEvents) Upsert

func (r RowEvents) Upsert(re RowEvent) RowEvents

Upsert add or update a row if it exists.

type RowSorter

type RowSorter struct {
	Rows                 Rows
	Index                int
	IsNumber, IsDuration 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 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 StringSet

type StringSet []string

StringSet represents a collection of unique strings.

func (StringSet) Add

func (ss StringSet) Add(item string) StringSet

Add adds a new item in the set.

func (StringSet) In

func (ss StringSet) In(item string) bool

In checks if a string is in the set.

type TableData

type TableData struct {
	Header    Header
	RowEvents RowEvents
	Namespace string
}

TableData tracks a K8s resource for tabular display.

func NewTableData

func NewTableData() *TableData

NewTableData returns a new table.

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

func (t *TableData) Customize(cols []string, wide bool) TableData

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(table TableData) bool

Diff checks if two tables are equal.

func (*TableData) IndexOfHeader

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

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

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

SetHeader sets table header.

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