ui

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Key0 tcell.Key = iota + 48
	Key1
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
)

Defines numeric keys for container actions.

View Source
const (
	KeyShift0 tcell.Key = 41
	KeyShift1 tcell.Key = 33
	KeyShift2 tcell.Key = 64
	KeyShift3 tcell.Key = 35
	KeyShift4 tcell.Key = 36
	KeyShift5 tcell.Key = 37
	KeyShift6 tcell.Key = 94
	KeyShift7 tcell.Key = 38
	KeyShift8 tcell.Key = 42
	KeyShift9 tcell.Key = 40
)

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
	KeySpace = 32
)

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.

View Source
const DropDownIndicatiorColor string = "green"
View Source
const DropdownPadSpaces int = 3

Variables

View Source
var LogoBig = []string{
	`█▀▀ █   █▀▀█ █  █ █▀▀▄ █   █▀▀ █▀▀▄ █▀▀`,
	`█   █   █  █ █  █ █  █ █   █▀▀ █  █ ▀▀█`,
	`▀▀▀ ▀▀▀ ▀▀▀▀  ▀▀▀ ▀▀▀  ▀▀▀ ▀▀▀ ▀  ▀ ▀▀▀`,
}

LogoBig cls big logo for splash page.

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

LogoSmall cls small log.

View Source
var NumKeys = map[int]tcell.Key{
	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 AsKey

func AsKey(evt *tcell.EventKey) tcell.Key

AsKey converts rune to keyboard key.,.

func SortMapByKeys

func SortMapByKeys(m map[string]tview.Primitive) map[string]tview.Primitive

func SortMapKeys

func SortMapKeys(m map[string]tview.Primitive) []string

func TrimCell

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

TrimCell removes superfluous padding.

Types

type ActionHandler

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

ActionHandler handles a keyboard command.

type App

type App struct {
	*tview.Application

	Main *Pages
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) AddActions

func (a *App) AddActions(aa KeyActions)

AddActions returns the application actions.

func (*App) BailOut

func (a *App) BailOut()

BailOut exits the application.

func (*App) BufferActive

func (a *App) BufferActive(state bool, kind model.BufferKind)

BufferActive indicates the buff activity changed.

func (*App) BufferChanged

func (a *App) BufferChanged(_, _ string)

BufferChanged indicates the buffer was changed.

func (*App) BufferCompleted

func (a *App) BufferCompleted(_, _ string)

BufferCompleted indicates input was accepted.

func (*App) CmdBuff

func (a *App) CmdBuff() *model.FishBuff

CmdBuff returns the app cmd model.

func (*App) Crumbs

func (a *App) Crumbs() *Crumbs

Crumbs return app crumbs.

func (*App) Flash

func (a *App) Flash() *model.Flash

Flash returns a flash model.

func (*App) FlashView

func (a *App) FlashView() *Flash

TODO: remove

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

func (a *App) HasAction(key tcell.Key) (KeyAction, bool)

HasAction checks if key matches a registered binding.

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

func (*App) IsRunning

func (a *App) IsRunning() bool

IsRunning checks if app is actually running.

func (*App) Menu

func (a *App) Menu() *Menu

Menu returns app menu.

func (*App) Prompt

func (a *App) Prompt() *Prompt

Prompt returns command prompt.

func (*App) QueueUpdate

func (a *App) QueueUpdate(f func())

QueueUpdate queues up a ui action.

func (*App) QueueUpdateDraw

func (a *App) QueueUpdateDraw(f func())

QueueUpdateDraw queues up a ui action and redraw the ui.

func (*App) ResetCmd

func (a *App) ResetCmd()

ResetCmd clear out user command.

func (*App) ResetPrompt

func (a *App) ResetPrompt(m PromptModel)

ResetPrompt reset the prompt model and marks buffer as active.

func (*App) SetRunning

func (a *App) SetRunning(f bool)

SetRunning sets the app run state.

func (*App) SuggestionChanged

func (a *App) SuggestionChanged(ss []string)

SuggestionChanged notifies of update to command suggestions.

func (*App) UpdateContext added in v0.1.4

func (a *App) UpdateContext(ctx context.Context)

func (*App) Views

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

Views return the application root views.

type CloudSelectionScreen added in v0.1.4

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

func NewCloudSelectionScreen added in v0.1.4

func NewCloudSelectionScreen(optionsWithAction OptionWithAction, version string) *CloudSelectionScreen

func (*CloudSelectionScreen) GetFocusItem added in v0.1.4

func (c *CloudSelectionScreen) GetFocusItem() *tview.List

type Crumbs

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

Crumbs represents user breadcrumbs.

func NewCrumbs

func NewCrumbs() *Crumbs

NewCrumbs returns a new breadcrumb view.

func (*Crumbs) StackPopped

func (c *Crumbs) StackPopped(_, _ model.Component)

StackPopped indicates an item was deleted.

func (*Crumbs) StackPushed

func (c *Crumbs) StackPushed(comp model.Component)

StackPushed indicates a new item was added.

func (*Crumbs) StackTop

func (c *Crumbs) StackTop(top model.Component)

StackTop indicates the top of the stack.

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

func NewDropDown

func NewDropDown(label string, options []string) *DropDown
func (d *DropDown) SetSelectedFn(selectedFn DropdownSelectedFn)
type DropdownSelectedFn func(text string, index int)

type Flash

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

Flash represents a flash message indicator.

func NewFlash

func NewFlash(app *App) *Flash

NewFlash returns a new flash view.

func (*Flash) SetMessage

func (f *Flash) SetMessage(m model.LevelMessage)

SetMessage sets flash message and level.

func (*Flash) SetTestMode

func (f *Flash) SetTestMode(b bool)

SetTestMode for testing ONLY!

func (*Flash) Watch

func (f *Flash) Watch(ctx context.Context, c model.FlashChan)

Watch watches for flash changes.

type Info

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

func NewInfo

func NewInfo(items map[string]tview.Primitive) *Info

type KeyAction

type KeyAction struct {
	Description string
	Action      ActionHandler
	Visible     bool
	Shared      bool
}

KeyAction represents a keyboard action.

func NewKeyAction

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

NewKeyAction returns a new keyboard action.

func NewSharedKeyAction

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

NewSharedKeyAction returns a new shared keyboard action.

type KeyActions

type KeyActions map[tcell.Key]KeyAction

KeyActions tracks mappings between keystrokes and actions.

func (KeyActions) Add

func (a KeyActions) Add(aa KeyActions)

Add sets up keyboard action listener.

func (KeyActions) Clear

func (a KeyActions) Clear()

Clear remove all actions.

func (KeyActions) Delete

func (a KeyActions) Delete(kk ...tcell.Key)

Delete deletes actions by the given keys.

func (KeyActions) Hints

func (a KeyActions) Hints() model.MenuHints

Hints returns a collection of hints.

func (KeyActions) Set

func (a KeyActions) Set(aa KeyActions)

Set replace actions with new ones.

type Lister

type Lister interface {
	// Get returns a resource instance.
	Get(ctx context.Context, path string) (dao.Object, error)
}

Lister represents a viewable resource.

type Logo struct {
	*tview.Flex
	// contains filtered or unexported fields
}
func NewLogo() *Logo
type Menu struct {
	*tview.Table
}

Menu presents menu options.

func NewMenu

func NewMenu() *Menu

NewMenu returns a new menu.

func (m *Menu) HydrateMenu(hh model.MenuHints)

HydrateMenu populate menu ui from hints.

func (m *Menu) StackPopped(o, top model.Component)

StackPopped notifies a component was removed.

func (m *Menu) StackPushed(c model.Component)

StackPushed notifies a component was added.

func (m *Menu) StackTop(t model.Component)

StackTop notifies the top component.

type OptionWithAction added in v0.1.4

type OptionWithAction map[string]func()

type Pages

type Pages struct {
	*tview.Pages
	*model.Stack
}

Pages represents a stack of view pages.

func NewPages

func NewPages() *Pages

NewPages return a new view.

func (*Pages) Current

func (p *Pages) Current() model.Component

Current returns the current component.

func (*Pages) Dump

func (p *Pages) Dump()

Dump for debug.

func (*Pages) IsTopDialog

func (p *Pages) IsTopDialog() bool

IsTopDialog checks if front page is a dialog.

func (*Pages) Show

func (p *Pages) Show(c model.Component)

Show displays a given page.

func (*Pages) StackPopped

func (p *Pages) StackPopped(o, top model.Component)

StackPopped notifies a component was removed.

func (*Pages) StackPushed

func (p *Pages) StackPushed(c model.Component)

StackPushed notifies a new component was pushed.

func (*Pages) StackTop

func (p *Pages) StackTop(top model.Component)

StackTop notifies a new component is at the top of the stack.

type Prompt

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

Prompt captures users free from command input.

func NewPrompt

func NewPrompt(app *App, noIcons bool) *Prompt

NewPrompt returns a new command view.

func (*Prompt) BufferActive

func (p *Prompt) BufferActive(activate bool, kind model.BufferKind)

BufferActive indicates the buff activity changed.

func (*Prompt) BufferChanged

func (p *Prompt) BufferChanged(text, suggestion string)

BufferChanged indicates the buffer was changed.

func (*Prompt) BufferCompleted

func (p *Prompt) BufferCompleted(text, suggestion string)

BufferCompleted indicates input was accepted.

func (*Prompt) InCmdMode

func (p *Prompt) InCmdMode() bool

InCmdMode returns true if command is active, false otherwise.

func (*Prompt) SendKey

func (p *Prompt) SendKey(evt *tcell.EventKey)

SendKey sends an keyboard event (testing only!).

func (*Prompt) SendStrokes

func (p *Prompt) SendStrokes(s string)

SendStrokes (testing only!)

func (*Prompt) SetModel

func (p *Prompt) SetModel(m PromptModel)

SetModel sets the prompt buffer model.

func (*Prompt) SuggestionChanged

func (p *Prompt) SuggestionChanged(text, suggestion string)

SuggestionChanged notifies the suggestion changed.

type PromptModel

type PromptModel interface {
	// SetText sets the model text.
	SetText(txt, sug string)

	// GetText returns the current text.
	GetText() string

	// GetSuggestion returns the current suggestion.
	GetSuggestion() string

	// ClearText clears out model text.
	ClearText(fire bool)

	// Notify notifies all listener of current suggestions.
	Notify(bool)

	// AddListener registers a command listener.
	AddListener(model.BuffWatcher)

	// RemoveListener removes a listener.
	RemoveListener(model.BuffWatcher)

	// IsActive returns true if prompt is active.
	IsActive() bool

	// SetActive sets whether the prompt is active or not.
	SetActive(bool)

	// Add adds a new char to the prompt.
	Add(rune)

	// Delete deletes the last prompt character.
	Delete()
}

PromptModel represents a prompt buffer.

type ResourceViewerListener

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

type SelectTable

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

SelectTable represents a table with selections.

func (*SelectTable) ClearMarks

func (s *SelectTable) ClearMarks()

ClearMarks delete all marked items.

func (*SelectTable) ClearSelection

func (s *SelectTable) ClearSelection()

ClearSelection reset selected row.

func (*SelectTable) DeleteMark

func (s *SelectTable) DeleteMark(k string)

DeleteMark delete a marked item.

func (*SelectTable) GetModel

func (s *SelectTable) GetModel() Tabular

GetModel returns the current model.

func (*SelectTable) GetRowID

func (s *SelectTable) GetRowID(index int) (string, bool)

GetRowID returns the row id at at given location.

func (*SelectTable) GetSecondColumn

func (s *SelectTable) GetSecondColumn() string

func (*SelectTable) GetSelectedCell

func (s *SelectTable) GetSelectedCell(col int) string

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

func (*SelectTable) GetSelectedItem

func (s *SelectTable) GetSelectedItem() string

GetSelectedItem returns the currently selected item name.

func (*SelectTable) GetSelectedItems

func (s *SelectTable) GetSelectedItems() []string

GetSelectedItems return currently marked or selected items names.

func (*SelectTable) GetSelectedRowIndex

func (s *SelectTable) GetSelectedRowIndex() int

GetSelectedRowIndex fetch the currently selected row index.

func (*SelectTable) IsMarked

func (s *SelectTable) IsMarked(item string) bool

IsMarked returns true if this item was marked.

func (*SelectTable) SelectFirstRow

func (s *SelectTable) SelectFirstRow()

SelectFirstRow select first data row if any.

func (*SelectTable) SelectRow

func (s *SelectTable) SelectRow(r int, broadcast bool)

SelectRow select a given row by index.

func (*SelectTable) SetModel

func (s *SelectTable) SetModel(m Tabular)

SetModel sets the table model.

func (*SelectTable) SetSelectedFn

func (s *SelectTable) SetSelectedFn(f func(string) string)

SetSelectedFn defines a function that cleanse the current selection.

func (*SelectTable) SpanMark

func (s *SelectTable) SpanMark()

SpanMark toggles marked row.

func (*SelectTable) ToggleMark

func (s *SelectTable) ToggleMark()

ToggleMark toggles marked row.

type SortColumn

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

SortColumn represents a sortable column.

type SortFn

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

SortFn represent a function that can sort columnar data.

type Splash

type Splash struct {
	*tview.Flex
}

func NewSplash

func NewSplash(version string) *Splash

type StatusIndicator

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

func NewStatusIndicator

func NewStatusIndicator(app *App) *StatusIndicator

NewStatusIndicator returns a new status indicator.

func (*StatusIndicator) SetPermanent

func (s *StatusIndicator) SetPermanent(info string)

SetPermanent sets permanent title to be reset to after updates.

type Suggester

type Suggester interface {
	// CurrentSuggestion returns the current suggestion.
	CurrentSuggestion() (string, bool)

	// NextSuggestion returns the next suggestion.
	NextSuggestion() (string, bool)

	// PrevSuggestion returns the prev suggestion.
	PrevSuggestion() (string, bool)

	// ClearSuggestions clear out all suggestions.
	ClearSuggestions()
}

Suggester provides suggestions.

type Table

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

Table represents tabular data.

func NewTable

func NewTable(res string) *Table

NewTable returns a new table view.

func (*Table) Actions

func (t *Table) Actions() KeyActions

Actions returns active menu bindings.

func (*Table) AddHeaderCell

func (t *Table) AddHeaderCell(col int, h render.HeaderColumn)

AddHeaderCell configures a table cell header.

func (*Table) ClearMarks

func (t *Table) ClearMarks()

ClearMarks clear out marked items.

func (*Table) Hints

func (t *Table) Hints() model.MenuHints

Hints returns the view hints.

func (*Table) Init

func (t *Table) Init(ctx context.Context)

Init initializes the component.

func (*Table) Refresh

func (t *Table) Refresh()

Refresh update the table data.

func (*Table) ResetToast

func (t *Table) ResetToast()

ResetToast resets toast flag.

func (*Table) Resource

func (t *Table) Resource() string

func (*Table) SortColCmd

func (t *Table) SortColCmd(name string, asc bool) func(evt *tcell.EventKey) *tcell.EventKey

SortColCmd designates a sorted column.

func (*Table) ToggleToast

func (t *Table) ToggleToast()

ToggleToast toggles to show toast resources.

func (*Table) ToggleWide

func (t *Table) ToggleWide()

ToggleWide toggles wide col display.

func (*Table) Update

func (t *Table) Update(data *render.TableData)

Update table content.

func (*Table) UpdateTitle

func (t *Table) UpdateTitle()

UpdateTitle refreshes the table title.

type Tabular

type Tabular interface {
	Lister

	// Empty returns true if model has no data.
	Empty() bool

	// Count returns the model data count.
	Count() int

	// Peek returns current model data.
	Peek() *render.TableData

	//Watch watches a given resource for changes.
	Watch(context.Context) error

	// Refresh forces a new refresh.
	Refresh(context.Context) error

	// SetRefreshRate sets the model watch loop rate.
	SetRefreshRate(time.Duration)

	// AddListener registers a model listener.
	AddListener(model.TableListener)

	// RemoveListener unregister a model listener.
	RemoveListener(model.TableListener)
}

Tabular represents a tabular model.

type Viewer

type Viewer interface {
	Lister
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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