ui

package
v0.0.0-...-8acee00 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DeltaSign signals a diff.
	DeltaSign = "Δ"
	// PlusSign signals inc.
	PlusSign = "↑"
	// MinusSign signal dec.
	MinusSign = "↓"
)
View Source
const (
	Key0 int32 = iota + 48
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
)

Defines numeric keys for container actions

View Source
const (
	KeyA tcell.Key = iota + 97
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
	KeyHelp  = 63
	KeySlash = 47
	KeyColon = 58
)

Defines char keystrokes

View Source
const (
	KeyShiftA tcell.Key = iota + 65
	KeyShiftB
	KeyShiftC
	KeyShiftD
	KeyShiftE
	KeyShiftF
	KeyShiftG
	KeyShiftH
	KeyShiftI
	KeyShiftJ
	KeyShiftK
	KeyShiftL
	KeyShiftM
	KeyShiftN
	KeyShiftO
	KeyShiftP
	KeyShiftQ
	KeyShiftR
	KeyShiftS
	KeyShiftT
	KeyShiftU
	KeyShiftV
	KeyShiftW
	KeyShiftX
	KeyShiftY
	KeyShiftZ
)

Define Shift Keys

Variables

View Source
var (
	// ModColor row modified color.
	ModColor tcell.Color
	// AddColor row added color.
	AddColor 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
	` ____  __.________      _________ .____    .___ `,
	`|    |/ _/   __   \_____\_   ___ \|    |   |   |`,
	`|      < \____    /  ___/    \  \/|    |   |   |`,
	`|    |  \   /    /\___ \\     \___|    |___|   |`,
	`|____|__ \ /____//____  >\______  /_______ \___|`,
	`        \/            \/        \/        \/    `,
}

Logo K9s big logo for splash page.

View Source
var LogoSmall = []string{
	` ____  __.________       `,
	`|    |/ _/   __   \______`,
	`|      < \____    /  ___/`,
	`|    |  \   /    /\___ \ `,
	`|____|__ \ /____//____  >`,
	`        \/            \/ `,
}

LogoSmall K9s small log.

View Source
var NumKeys = map[int]int32{
	0: Key0,
	1: Key1,
	2: Key2,
	3: Key3,
	4: Key4,
	5: Key5,
	6: Key6,
	7: Key7,
	8: Key8,
	9: Key9,
}

NumKeys tracks number keys.

Functions

func BenchConfig

func BenchConfig(cluster string) string

BenchConfig location of the benchmarks configuration file.

func ComputeMaxColumns

func ComputeMaxColumns(pads MaxyPad, sortCol int, table resource.TableData)

ComputeMaxColumns figures out column max size and necessary padding.

func DefaultColorer

func DefaultColorer(ns string, r *resource.RowEvent) tcell.Color

DefaultColorer set the default table row colors.

func Deltas

func Deltas(o, n string) string

Deltas signals diffs between 2 strings.

func IsASCII

func IsASCII(s string) bool

IsASCII checks if table cell has all ascii characters.

func Pad

func Pad(s string, width int) string

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

func TrimCell

func TrimCell(tv *Table, row, col int) string

TrimCell removes superfluous padding.

Types

type ActionHandler

type ActionHandler func(*tcell.EventKey) *tcell.EventKey

ActionHandler handles a keyboard command.

type ActionsFunc

type ActionsFunc func(KeyActions)

ActionsFunc augments Keybindings.

type App

type App struct {
	*tview.Application
	Configurator
	// contains filtered or unexported fields
}

App represents an application.

func NewApp

func NewApp() *App

NewApp returns a new app.

func (*App) ActivateCmd

func (a *App) ActivateCmd(b bool)

ActivateCmd toggle command mode.

func (*App) ActiveView

func (a *App) ActiveView() Igniter

ActiveView returns the currently active view.

func (*App) AddActions

func (a *App) AddActions(aa KeyActions)

AddActions returns the application actions.

func (*App) BailOut

func (a *App) BailOut()

BailOut exists the application.

func (*App) Cmd

func (a *App) Cmd() *CmdView

Cmd returns app cmd.

func (*App) Conn

func (a *App) Conn() k8s.Connection

Conn returns an api server connection.

func (*App) Crumbs

func (a *App) Crumbs() *CrumbsView

Crumbs return app crumbs.

func (*App) Flash

func (a *App) Flash() *FlashView

Flash returns app flash.

func (*App) Frame

func (a *App) Frame() *tview.Pages

Frame returns main app content frame.

func (*App) GetActions

func (a *App) GetActions() KeyActions

GetActions returns a collection of actions.

func (*App) GetCmd

func (a *App) GetCmd() string

GetCmd retrieves user command.

func (*App) GetCmdBuff

func (a *App) GetCmdBuff() *CmdBuff

GetCmdBuff returns a cmd buffer.

func (*App) GetHints

func (a *App) GetHints() Hints

GetHints retrieves the currently active hints.

func (*App) HasCmd

func (a *App) HasCmd() bool

HasCmd check if cmd buffer is active and has a command.

func (*App) InCmdMode

func (a *App) InCmdMode() bool

InCmdMode check if command mode is active.

func (*App) Init

func (a *App) Init()

Init initializes the application.

func (a *App) Logo() *LogoView

Logo return the app logo.

func (*App) Main

func (a *App) Main() *tview.Pages

Main returns main app frame.

func (*App) Menu

func (a *App) Menu() *MenuView

Menu returns app menu.

func (*App) ResetCmd

func (a *App) ResetCmd()

ResetCmd clear out user command.

func (*App) SetHints

func (a *App) SetHints(h Hints)

SetHints updates menu hints.

func (*App) StatusReset

func (a *App) StatusReset()

StatusReset reset log back to normal.

func (*App) Views

func (a *App) Views() map[string]tview.Primitive

Views return the application root views.

type CmdBuff

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

CmdBuff represents user command input.

func NewCmdBuff

func NewCmdBuff(key rune) *CmdBuff

NewCmdBuff returns a new command buffer.

func (*CmdBuff) Add

func (c *CmdBuff) Add(r rune)

Add adds a new charater to the buffer.

func (*CmdBuff) AddListener

func (c *CmdBuff) AddListener(w ...buffWatcher)

AddListener registers a cmd buffer listener.

func (*CmdBuff) Clear

func (c *CmdBuff) Clear()

Clear clears out command buffer.

func (*CmdBuff) Delete

func (c *CmdBuff) Delete()

Delete removes the last character from the buffer.

func (*CmdBuff) Empty

func (c *CmdBuff) Empty() bool

Empty returns true is no cmd, false otherwise.

func (*CmdBuff) IsActive

func (c *CmdBuff) IsActive() bool

IsActive checks if command buffer is active.

func (*CmdBuff) Reset

func (c *CmdBuff) Reset()

Reset clears out the command buffer.

func (*CmdBuff) Set

func (c *CmdBuff) Set(rr []rune)

Set initializes the buffer with a command.

func (*CmdBuff) SetActive

func (c *CmdBuff) SetActive(b bool)

SetActive toggles cmd buffer active state.

func (*CmdBuff) String

func (c *CmdBuff) String() string

String turns rune to string (Stringer protocol)

type CmdStack

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

CmdStack tracks users command breadcrumbs.

func NewCmdStack

func NewCmdStack() *CmdStack

NewCmdStack returns a new cmd stack.

func (*CmdStack) Empty

func (s *CmdStack) Empty() bool

Empty check if stack is empty.

func (*CmdStack) Items

func (s *CmdStack) Items() []string

Items returns current stack content.

func (*CmdStack) Last

func (s *CmdStack) Last() bool

Last returns the last command.

func (*CmdStack) Pop

func (s *CmdStack) Pop() (string, bool)

Pop delete an item.

func (*CmdStack) Push

func (s *CmdStack) Push(cmd string)

Push adds a new item,

func (*CmdStack) Top

func (s *CmdStack) Top() (string, bool)

Top return top element.

type CmdView

type CmdView struct {
	*tview.TextView
	// contains filtered or unexported fields
}

CmdView captures users free from command input.

func NewCmdView

func NewCmdView(styles *config.Styles, ic rune) *CmdView

NewCmdView returns a new command view.

func (*CmdView) InCmdMode

func (v *CmdView) InCmdMode() bool

InCmdMode returns true if command is active, false otherwise.

type ColorerFunc

type ColorerFunc func(ns string, evt *resource.RowEvent) tcell.Color

ColorerFunc represents a row colorer.

type Configurator

type Configurator struct {
	HasSkins bool
	Config   *config.Config
	Styles   *config.Styles
	Bench    *config.Bench
}

Configurator represents an application configurations.

func (*Configurator) InitBench

func (c *Configurator) InitBench(cluster string)

InitBench load benchmark configuration if any.

func (*Configurator) RefreshStyles

func (c *Configurator) RefreshStyles()

RefreshStyles load for skin configuration changes.

func (*Configurator) StylesUpdater

func (c *Configurator) StylesUpdater(ctx context.Context, s synchronizer) error

StylesUpdater watches for skin file changes.

type CrumbsView

type CrumbsView struct {
	*tview.TextView
	// contains filtered or unexported fields
}

CrumbsView represents user breadcrumbs.

func NewCrumbsView

func NewCrumbsView(styles *config.Styles) *CrumbsView

NewCrumbsView returns a new breadcrumb view.

func (*CrumbsView) Refresh

func (v *CrumbsView) Refresh(crumbs []string)

Refresh updates view with new crumbs.

type FlashLevel

type FlashLevel int

FlashLevel represents flash message severity.

const (
	// FlashInfo represents an info message.
	FlashInfo FlashLevel = iota
	// FlashWarn represents an warning message.
	FlashWarn
	// FlashErr represents an error message.
	FlashErr
	// FlashFatal represents an fatal message.
	FlashFatal
)

type FlashView

type FlashView struct {
	*tview.TextView
	// contains filtered or unexported fields
}

FlashView represents a flash message indicator.

func NewFlashView

func NewFlashView(app *tview.Application, m string) *FlashView

NewFlashView returns a new flash view.

func (*FlashView) Err

func (v *FlashView) Err(err error)

Err displays an error flash message.

func (*FlashView) Errf

func (v *FlashView) Errf(fmat string, args ...interface{})

Errf displays a formatted error flash message.

func (*FlashView) Info

func (v *FlashView) Info(msg string)

Info displays an info flash message.

func (*FlashView) Infof

func (v *FlashView) Infof(fmat string, args ...interface{})

Infof displays a formatted info flash message.

func (*FlashView) Warn

func (v *FlashView) Warn(msg string)

Warn displays a warning flash message.

func (*FlashView) Warnf

func (v *FlashView) Warnf(fmat string, args ...interface{})

Warnf displays a formatted warning flash message.

type GroupSorter

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

GroupSorter sorts a collection of rows.

func (GroupSorter) Len

func (s GroupSorter) Len() int

func (GroupSorter) Less

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

func (GroupSorter) Swap

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

type Hint

type Hint struct {
	Mnemonic, Description string
}

Hint represents keyboard mnemonic.

type Hinter

type Hinter interface {
	Hints() Hints
}

Hinter returns a collection of mnemonics.

type Hints

type Hints []Hint

Hints a collection of keyboard mnemonics.

func (Hints) Len

func (h Hints) Len() int

func (Hints) Less

func (h Hints) Less(i, j int) bool

func (Hints) Swap

func (h Hints) Swap(i, j int)

type Igniter

type Igniter interface {
	tview.Primitive

	// Init initializes the view.
	Init(ctx context.Context, ns string)
}

Igniter represents an initializable view.

type IndicatorView

type IndicatorView struct {
	*tview.TextView
	// contains filtered or unexported fields
}

IndicatorView represents a status indicator.

func NewIndicatorView

func NewIndicatorView(app *App, styles *config.Styles) *IndicatorView

NewIndicatorView returns a new logo.

func (*IndicatorView) Err

func (v *IndicatorView) Err(msg string)

Err displays a log error state.

func (*IndicatorView) Info

func (v *IndicatorView) Info(msg string)

Info displays a log info state.

func (*IndicatorView) Reset

func (v *IndicatorView) Reset()

Reset clears out the logo view and resets colors.

func (*IndicatorView) SetPermanent

func (v *IndicatorView) SetPermanent(info string)

SetPermanent sets permanent title to be reset to after updates

func (*IndicatorView) Warn

func (v *IndicatorView) Warn(msg string)

Warn displays a log warning state.

type KeyAction

type KeyAction struct {
	Description string
	Action      ActionHandler
	Visible     bool
}

KeyAction represents a keyboard action.

func NewKeyAction

func NewKeyAction(d string, a ActionHandler, display bool) KeyAction

NewKeyAction returns a new keyboard action.

type KeyActions

type KeyActions map[tcell.Key]KeyAction

KeyActions tracks mappings between keystrokes and actions.

func (KeyActions) Hints

func (a KeyActions) Hints() Hints

Hints returns a collection of hints.

type LogoView

type LogoView struct {
	*tview.Flex
	// contains filtered or unexported fields
}

LogoView represents a K9s logo.

func NewLogoView

func NewLogoView(styles *config.Styles) *LogoView

NewLogoView returns a new logo.

func (*LogoView) Err

func (v *LogoView) Err(msg string)

Err displays a log error state.

func (*LogoView) Info

func (v *LogoView) Info(msg string)

Info displays a log info state.

func (*LogoView) Reset

func (v *LogoView) Reset()

Reset clears out the logo view and resets colors.

func (*LogoView) Warn

func (v *LogoView) Warn(msg string)

Warn displays a log warning state.

type MaxyPad

type MaxyPad []int

MaxyPad tracks uniform column padding.

type MenuView struct {
	*tview.Table
	// contains filtered or unexported fields
}

MenuView represents menu options.

func NewMenuView

func NewMenuView(styles *config.Styles) *MenuView

NewMenuView returns a new menu.

func (v *MenuView) HydrateMenu(hh Hints)

HydrateMenu populate menu ui from hints.

type RowSorter

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

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 SelectedRowFunc

type SelectedRowFunc func(r, c int)

SelectedRowFunc a table selection callback.

type SortColumn

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

SortColumn represents a sortable column.

type SortFn

type SortFn func(rows resource.Rows, sortCol SortColumn)

SortFn represent a function that can sort columnar data.

type SplashView

type SplashView struct {
	*tview.Flex
}

SplashView represents a splash screen.

func NewSplash

func NewSplash(styles *config.Styles, version string) *SplashView

NewSplash instantiates a new splash screen with product and company info.

type Table

type Table struct {
	*tview.Table
	// contains filtered or unexported fields
}

Table represents tabular data.

func NewTable

func NewTable(title string, styles *config.Styles) *Table

NewTable returns a new table view.

func (*Table) ActiveNS

func (v *Table) ActiveNS() string

ActiveNS get the resource namespace.

func (*Table) AddHeaderCell

func (v *Table) AddHeaderCell(numerical bool, col int, name string)

AddHeaderCell configures a table cell header.

func (*Table) AddSelectedRowListener

func (v *Table) AddSelectedRowListener(f SelectedRowFunc)

AddSelectedRowListener add a new selected row listener.

func (*Table) ClearSelection

func (v *Table) ClearSelection()

ClearSelection reset selected row.

func (*Table) Cmd

func (v *Table) Cmd() *CmdBuff

Cmd returns the associated command buffer.

func (*Table) GetBaseTitle

func (v *Table) GetBaseTitle() string

GetBaseTitle fetch the current title.

func (*Table) GetData

func (v *Table) GetData() resource.TableData

GetData fetch tabular data.

func (*Table) GetRow

func (v *Table) GetRow() resource.Row

GetRow retrieves the entire selected row.

func (*Table) GetSelectedCell

func (v *Table) GetSelectedCell(col int) string

GetSelectedCell returns the contant of a cell for the currently selected row.

func (*Table) GetSelectedItem

func (v *Table) GetSelectedItem() string

GetSelectedItem returns the currently selected item name.

func (*Table) GetSelectedRow

func (v *Table) GetSelectedRow() int

GetSelectedRow fetch the currently selected row index.

func (*Table) Hints

func (v *Table) Hints() Hints

Hints options

func (*Table) KeyBindings

func (v *Table) KeyBindings() KeyActions

KeyBindings returns the bounded keys.

func (*Table) NameColIndex

func (v *Table) NameColIndex() int

NameColIndex returns the index of the resource name column.

func (*Table) Refresh

func (v *Table) Refresh()

Refresh update the table data.

func (*Table) RmAction

func (v *Table) RmAction(kk ...tcell.Key)

RmAction delete a keyed action.

func (*Table) RowSelected

func (v *Table) RowSelected() bool

RowSelected checks if there is an active row selection.

func (*Table) SelectFirstRow

func (v *Table) SelectFirstRow()

SelectFirstRow select first data row if any.

func (*Table) SelectRow

func (v *Table) SelectRow(r int, broadcast bool)

SelectRow select a given row by index.

func (*Table) SetActions

func (v *Table) SetActions(aa KeyActions)

SetActions sets up keyboard action listener.

func (*Table) SetActiveNS

func (v *Table) SetActiveNS(ns string)

SetActiveNS set the resource namespace.

func (*Table) SetBaseTitle

func (v *Table) SetBaseTitle(s string)

SetBaseTitle set the table title.

func (*Table) SetColorerFn

func (v *Table) SetColorerFn(f ColorerFunc)

SetColorerFn set the row colorer.

func (*Table) SetSelectedFn

func (v *Table) SetSelectedFn(f func(string) string)

SetSelectedFn defines a function that cleanse the current selection.

func (*Table) SetSortCol

func (v *Table) SetSortCol(index, count int, asc bool)

SetSortCol sets in sort column index and order.

func (*Table) ShowDeleted

func (v *Table) ShowDeleted()

ShowDeleted marks row as deleted.

func (*Table) SortColCmd

func (v *Table) SortColCmd(col int) func(evt *tcell.EventKey) *tcell.EventKey

SortColCmd designates a sorted column.

func (*Table) SortInvertCmd

func (v *Table) SortInvertCmd(evt *tcell.EventKey) *tcell.EventKey

SortInvertCmd reverses sorting order.

func (*Table) Update

func (v *Table) Update(data resource.TableData)

Update table content.

func (*Table) UpdateTitle

func (v *Table) UpdateTitle()

UpdateTitle refreshes the table title.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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