model

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REFRESH int64 = 1
	MAIL    int64 = 2
)
View Source
const MaxHistory = 20

MaxHistory tracks max command history.

Variables

View Source
var Registry = map[string]ResourceMeta{
	"process": {
		Renderer: &render.Process{},
	},
	"namespace": {
		Renderer: &render.Namespace{},
	},
}

Registry tracks resources metadata.

Functions

func NewExpBackOff

func NewExpBackOff(ctx context.Context, start, max time.Duration) backoff.BackOffContext

NewExpBackOff returns a new exponential backoff timer.

func NormalizeVersion

func NormalizeVersion(version string) string

NormalizeVersion ensures the version starts with a v.

func Truncate

func Truncate(str string, width int) string

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

Types

type BuffWatcher

type BuffWatcher interface {
	// BufferCompleted indicates input was accepted.
	BufferCompleted(text, suggestion string)

	// BufferChanged indicates the buffer was changed.
	BufferChanged(text, suggestion string)

	// BufferActive indicates the buff activity changed.
	BufferActive(state bool, kind BufferKind)
}

BuffWatcher represents a command buffer listener.

type BufferKind

type BufferKind int8

BufferKind indicates a buffer type.

const (

	// CommandBuffer represents a command buffer.
	CommandBuffer BufferKind = 1 << iota
	// FilterBuffer represents a filter buffer.
	FilterBuffer
)

type Cluster

type Cluster struct {
	Total, Healthy, Killed, PortClosed, Node int
}

type CmdBuff

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

CmdBuff represents user command input.

func NewCmdBuff

func NewCmdBuff(key rune, kind BufferKind) *CmdBuff

NewCmdBuff returns a new command buffer.

func (*CmdBuff) Add

func (c *CmdBuff) Add(r rune)

Add adds a new character to the buffer.

func (*CmdBuff) AddListener

func (c *CmdBuff) AddListener(w BuffWatcher)

AddListener registers a cmd buffer listener.

func (*CmdBuff) ClearText

func (c *CmdBuff) ClearText(fire bool)

ClearText 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 if no cmd, false otherwise.

func (*CmdBuff) GetSuggestion

func (c *CmdBuff) GetSuggestion() string

GetSuggestion returns the current suggestion.

func (*CmdBuff) GetText

func (c *CmdBuff) GetText() string

GetText returns the current text.

func (*CmdBuff) InCmdMode

func (c *CmdBuff) InCmdMode() bool

InCmdMode checks if a command exists and the buffer is active.

func (*CmdBuff) IsActive

func (c *CmdBuff) IsActive() bool

IsActive checks if command buffer is active.

func (*CmdBuff) RemoveListener

func (c *CmdBuff) RemoveListener(l BuffWatcher)

RemoveListener removes a listener.

func (*CmdBuff) Reset

func (c *CmdBuff) Reset()

Reset clears out the command buffer and deactivates it.

func (*CmdBuff) SetActive

func (c *CmdBuff) SetActive(b bool)

SetActive toggles cmd buffer active state.

func (*CmdBuff) SetText

func (c *CmdBuff) SetText(text, suggestion string)

SetText initializes the buffer with a command.

type Commander

type Commander interface {
	// InCmdMode checks if prompt is active.
	InCmdMode() bool
}

Commander tracks prompt status.

type Component

type Component interface {
	Primitive
	Igniter
	Hinter
	Commander
}

Component represents a ui component.

type Filterable

type Filterable interface {
	Filter(string)
	ClearFilter()
}

Filterable represents an entity that can be filtered.

type FishBuff

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

FishBuff represents a suggestion buffer.

func NewFishBuff

func NewFishBuff(key rune, kind BufferKind) *FishBuff

NewFishBuff returns a new command buffer.

func (*FishBuff) Add

func (f *FishBuff) Add(r rune)

Add adds a new character to the buffer.

func (*FishBuff) AutoSuggests

func (f *FishBuff) AutoSuggests() bool

AutoSuggests returns true if model implements auto suggestions.

func (*FishBuff) ClearSuggestions

func (f *FishBuff) ClearSuggestions()

ClearSuggestions clear out all suggestions.

func (*FishBuff) CurrentSuggestion

func (f *FishBuff) CurrentSuggestion() (string, bool)

CurrentSuggestion returns the current suggestion.

func (*FishBuff) Delete

func (f *FishBuff) Delete()

Delete removes the last character from the buffer.

func (*FishBuff) NextSuggestion

func (f *FishBuff) NextSuggestion() (string, bool)

NextSuggestion returns the next suggestion.

func (*FishBuff) Notify

func (f *FishBuff) Notify(delete bool)

Notify publish suggestions to all listeners.

func (*FishBuff) PrevSuggestion

func (f *FishBuff) PrevSuggestion() (string, bool)

PrevSuggestion returns the prev suggestion.

func (*FishBuff) SetSuggestionFn

func (f *FishBuff) SetSuggestionFn(fn SuggestionFunc)

SetSuggestionFn sets up suggestions.

func (*FishBuff) Suggestions

func (f *FishBuff) Suggestions() []string

Suggestions returns suggestions.

type Flash

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

Flash represents a flash message model.

func NewFlash

func NewFlash(dur time.Duration) *Flash

NewFlash returns a new instance.

func (*Flash) Channel

func (f *Flash) Channel() FlashChan

Channel returns the flash channel.

func (*Flash) Clear

func (f *Flash) Clear()

Clear clears the flash message.

func (*Flash) Err

func (f *Flash) Err(err error)

Err displays an error flash message.

func (*Flash) Errf

func (f *Flash) Errf(fmat string, args ...interface{})

Errf displays a formatted error flash message.

func (*Flash) Info

func (f *Flash) Info(msg string)

Info displays an info flash message.

func (*Flash) Infof

func (f *Flash) Infof(fmat string, args ...interface{})

Infof displays a formatted info flash message.

func (*Flash) SetMessage

func (f *Flash) SetMessage(level FlashLevel, msg string)

SetMessage sets the flash level message.

func (*Flash) Warn

func (f *Flash) Warn(msg string)

Warn displays a warning flash message.

func (*Flash) Warnf

func (f *Flash) Warnf(fmat string, args ...interface{})

Warnf displays a formatted warning flash message.

type FlashChan

type FlashChan chan LevelMessage

FlashChan represents a flash event channel.

type FlashLevel

type FlashLevel int

FlashLevel represents flash message severity.

const (
	// DefaultFlashDelay sets the flash clear delay.
	DefaultFlashDelay = 3 * time.Second

	// FlashInfo represents an info message.
	FlashInfo FlashLevel = iota
	// FlashWarn represents an warning message.
	FlashWarn
	// FlashErr represents an error message.
	FlashErr
)

type FlashListener

type FlashListener interface {
	// FlashChanged notifies the model changed.
	FlashChanged(FlashLevel, string)

	// FlashCleared notifies when the filter changed.
	FlashCleared()
}

FlashListener represents a text model listener.

type Hint

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

Hint represent a hint model.

func NewHint

func NewHint() *Hint

NewHint return new hint model.

func (*Hint) AddListener

func (h *Hint) AddListener(l HintListener)

AddListener adds a hint listener.

func (*Hint) Peek

func (h *Hint) Peek() MenuHints

Peek returns the model data.

func (*Hint) RemoveListener

func (h *Hint) RemoveListener(l HintListener)

RemoveListener deletes a listener.

func (*Hint) SetHints

func (h *Hint) SetHints(hh MenuHints)

SetHints set model hints.

type HintListener

type HintListener interface {
	HintsChanged(MenuHints)
}

HintListener represents a menu hints listener.

type Hinter

type Hinter interface {
	// Hints returns a collection of menu hints.
	Hints() MenuHints

	// ExtraHints returns additional hints.
	ExtraHints() map[string]string
}

Hinter represent a menu mnemonic provider.

type History

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

History represents a command history.

func NewHistory

func NewHistory(limit int) *History

NewHistory returns a new instance.

func (*History) Clear

func (h *History) Clear()

Clear clears out the stack.

func (*History) Empty

func (h *History) Empty() bool

Empty returns true if no history.

func (*History) List

func (h *History) List() []string

List returns the current command history.

func (*History) Push

func (h *History) Push(c string)

Push adds a new item.

type Igniter

type Igniter interface {
	Init(ctx context.Context) error

	// Start starts a component.
	Start()

	// Stop terminates a component.
	Stop()
}

Igniter represents a runnable view.

type LevelMessage

type LevelMessage struct {
	Level FlashLevel
	Text  string
}

LevelMessage tracks an message and severity.

func (LevelMessage) IsClear

func (l LevelMessage) IsClear() bool

IsClear returns true if message is empty.

type MenuHint struct {
	Mnemonic    string
	Description string
	Visible     bool
}

MenuHint represents keyboard mnemonic.

func (m MenuHint) IsBlank() bool

IsBlank checks if menu hint is a place holder.

func (m MenuHint) String() string

String returns a string representation.

type MenuHints []MenuHint

MenuHints represents a collection of hints.

func (h MenuHints) Len() int

Len returns the hints length.

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

Less returns true if first hint is less than second.

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

Swap swaps to elements.

type MyTable

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

MyTable represents a table model.

func NewMyTable

func NewMyTable(cat string) *MyTable

NewMyTable returns a new table model.

func (*MyTable) AddListener

func (t *MyTable) AddListener(l TableListener)

AddListener adds a new model listener.

func (*MyTable) ClusterWide

func (t *MyTable) ClusterWide() bool

ClusterWide checks if resource is scope for all namespaces.

func (*MyTable) Count

func (t *MyTable) Count() int

Count returns the row count.

func (*MyTable) Delete

func (t *MyTable) Delete(ctx context.Context, path string, cascade, force bool) error

Delete deletes a resource.

func (*MyTable) Empty

func (t *MyTable) Empty() bool

Empty returns true if no model data.

func (*MyTable) GetNamespace

func (t *MyTable) GetNamespace() string

GetNamespace returns the model namespace.

func (*MyTable) InNamespace

func (t *MyTable) InNamespace(ns string) bool

InNamespace checks if current namespace matches desired namespace.

func (*MyTable) Peek

func (t *MyTable) Peek() render.TableData

Peek returns model data.

func (*MyTable) Refresh

func (t *MyTable) Refresh(ctx context.Context) error

Refresh updates the table content.

func (*MyTable) RemoveListener

func (t *MyTable) RemoveListener(l TableListener)

RemoveListener delete a listener from the list.

func (*MyTable) SendCommand

func (t *MyTable) SendCommand(ctx context.Context, key int64) error

func (*MyTable) SetInstance

func (t *MyTable) SetInstance(path string)

SetInstance sets a single entry table.

func (*MyTable) SetLabelFilter

func (t *MyTable) SetLabelFilter(f string)

SetLabelFilter sets the labels filter.

func (*MyTable) SetNamespace

func (t *MyTable) SetNamespace(ns string)

SetNamespace sets up model namespace.

func (*MyTable) SetRefreshRate

func (t *MyTable) SetRefreshRate(d time.Duration)

SetRefreshRate sets model refresh duration.

func (*MyTable) Watch

func (t *MyTable) Watch(ctx context.Context) error

Watch initiates model updates.

type Primitive

type Primitive interface {
	tview.Primitive

	// Name returns the view name.
	Name() string
}

Primitive represents a UI primitive.

type Renderer

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

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

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

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

Renderer represents a resource renderer.

type ResourceMeta

type ResourceMeta struct {
	//DAO          dao.Accessor
	Renderer     Renderer
	TreeRenderer TreeRenderer
}

ResourceMeta represents model info about a resource.

type ResourceViewer

type ResourceViewer interface {
	GetPath() string
	Filter(string)
	ClearFilter()
	Peek() []string
	SetOptions(context.Context, ViewerToggleOpts)
	Watch(context.Context) error
	Refresh(context.Context) error
	AddListener(ResourceViewerListener)
	RemoveListener(ResourceViewerListener)
}

ResourceViewer represents a viewed resource.

type ResourceViewerListener

type ResourceViewerListener interface {
	ResourceChanged(lines []string, matches fuzzy.Matches)
	ResourceFailed(error)
}

ResourceViewerListener listens to viewing resource events.

type SemVer

type SemVer struct {
	Major, Minor, Patch int
}

SemVer represents a semantic version.

func NewSemVer

func NewSemVer(version string) *SemVer

NewSemVer returns a new semantic version.

func (*SemVer) IsCurrent

func (v *SemVer) IsCurrent(latest *SemVer) bool

IsCurrent asserts if at latest release.

func (*SemVer) String

func (v *SemVer) String() string

String returns version as a string.

type SilentStack

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

SilentStack represents a stacks of components.

func NewSilentStack

func NewSilentStack() *SilentStack

NewSilentStack returns a new initialized stack.

func (*SilentStack) Clear

func (s *SilentStack) Clear()

Clear clears out the stack using pops.

func (*SilentStack) Dump

func (s *SilentStack) Dump()

Dump prints out the stack.

func (*SilentStack) Empty

func (s *SilentStack) Empty() bool

Empty returns true if the stack is empty.

func (*SilentStack) Flatten

func (s *SilentStack) Flatten() []string

Flatten returns a string representation of the component stack.

func (*SilentStack) IsLast

func (s *SilentStack) IsLast() bool

IsLast indicates if stack only has one item left.

func (*SilentStack) Peek

func (s *SilentStack) Peek() []Component

Peek returns stack state.

func (*SilentStack) Pop

func (s *SilentStack) Pop() (Component, bool)

Pop removed the top item and returns it.

func (*SilentStack) Previous

func (s *SilentStack) Previous() Component

Previous returns the previous component if any.

func (*SilentStack) Push

func (s *SilentStack) Push(c Component)

Push adds a new item.

func (*SilentStack) Top

func (s *SilentStack) Top() Component

Top returns the top most item or nil if the stack is empty.

type Stack

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

Stack represents a stacks of components.

func NewStack

func NewStack() *Stack

NewStack returns a new initialized stack.

func (*Stack) AddListener

func (s *Stack) AddListener(l StackListener)

AddListener registers a stack listener.

func (*Stack) Clear

func (s *Stack) Clear()

Clear clear out the stack using pops.

func (*Stack) Dump

func (s *Stack) Dump()

Dump prints out the stack.

func (*Stack) Empty

func (s *Stack) Empty() bool

Empty returns true if the stack is empty.

func (*Stack) Flatten

func (s *Stack) Flatten() []string

Flatten returns a string representation of the component stack.

func (*Stack) IsLast

func (s *Stack) IsLast() bool

IsLast indicates if stack only has one item left.

func (*Stack) Peek

func (s *Stack) Peek() []Component

Peek returns stack state.

func (*Stack) Pop

func (s *Stack) Pop() (Component, bool)

Pop removed the top item and returns it.

func (*Stack) Previous

func (s *Stack) Previous() Component

Previous returns the previous component if any.

func (*Stack) Push

func (s *Stack) Push(c Component)

Push adds a new item.

func (*Stack) RemoveListener

func (s *Stack) RemoveListener(l StackListener)

RemoveListener removes a listener.

func (*Stack) Top

func (s *Stack) Top() Component

Top returns the top most item or nil if the stack is empty.

type StackAction

type StackAction int

StackAction represents an action on the stack.

const (
	// StackPush denotes an add on the stack.
	StackPush StackAction = 1 << iota

	// StackPop denotes a delete on the stack.
	StackPop
)

type StackEvent

type StackEvent struct {
	// Kind represents the event condition.
	Action StackAction

	// Item represents the targeted item.
	Component Component
}

StackEvent represents an operation on a view stack.

type StackListener

type StackListener interface {
	// StackPushed indicates a new item was added.
	StackPushed(Component)

	// StackPopped indicates an item was deleted
	StackPopped(old, new Component)

	// StackTop indicates the top of the stack
	StackTop(Component)
}

StackListener represents a stack listener.

type SuggestionFunc

type SuggestionFunc func(text string) sort.StringSlice

SuggestionFunc produces suggestions.

type SuggestionListener

type SuggestionListener interface {
	BuffWatcher

	// SuggestionChanged notifies suggestion changes.
	SuggestionChanged(text, sugg string)
}

SuggestionListener listens for suggestions.

type TableListener

type TableListener interface {
	// TableDataChanged notifies the model data changed.
	TableDataChanged(render.TableData)

	// TableLoadFailed notifies the load failed.
	TableLoadFailed(error)
}

TableListener represents a table model listener.

type Text

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

Text represents a text model.

func NewText

func NewText() *Text

NewText returns a new model.

func (*Text) AddListener

func (t *Text) AddListener(listener TextListener)

AddListener adds a new model listener.

func (*Text) ClearFilter

func (t *Text) ClearFilter()

ClearFilter clear out filter.

func (*Text) Filter

func (t *Text) Filter(q string)

Filter filters out the text.

func (*Text) Peek

func (t *Text) Peek() []string

Peek returns the current model state.

func (*Text) RemoveListener

func (t *Text) RemoveListener(listener TextListener)

RemoveListener delete a listener from the list.

func (*Text) SetText

func (t *Text) SetText(buff string)

SetText sets the current model content.

type TextListener

type TextListener interface {
	// TextChanged notifies the model changed.
	TextChanged([]string)

	// TextFiltered notifies when the filter changed.
	TextFiltered([]string, fuzzy.Matches)
}

TextListener represents a text model listener.

type Textable

type Textable interface {
	Peek() []string
	SetText(string)
	AddListener(TextListener)
	RemoveListener(TextListener)
}

Textable represents a text resource.

type TreeRenderer

type TreeRenderer interface {
	Render(ctx context.Context, ns string, o interface{}) error
}

TreeRenderer represents an xray node.

type ViewerToggleOpts

type ViewerToggleOpts map[string]bool

ViewerToggleOpts represents a collection of viewing options.

Jump to

Keyboard shortcuts

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