ui

package
v0.0.0-...-0798a42 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BORDER_LEFT   = 1 << iota
	BORDER_TOP    = 1 << iota
	BORDER_RIGHT  = 1 << iota
	BORDER_BOTTOM = 1 << iota
)
View Source
const (
	SIZE_EXACT  = iota
	SIZE_WEIGHT = iota
)
View Source
const (
	TEXT_LEFT   = iota
	TEXT_CENTER = iota
	TEXT_RIGHT  = iota
)

Variables

View Source
var Callbacks = make(chan func(), 50)
View Source
var Events = make(chan vaxis.Event)

Use unbuffered channels (always blocking unless somebody can read immediately) We are merely using this as a proxy to the internal vaxis event channel.

View Source
var Quit = make(chan struct{})
View Source
var Redraw = make(chan bool, 1)

Use a buffered channel of size 1 to avoid blocking callers of Invalidate()

View Source
var SuspendQueue = make(chan bool, 1)

Functions

func ApplyAttrs

func ApplyAttrs(ss *vaxis.StyledString, style vaxis.Style)

ApplyAttrs applies the style, and if another style is present ORs the attributes

func ApplyStyle

func ApplyStyle(style vaxis.Style, str string) string

Applies a style to a string. Any currently applied styles will not be overwritten

func Close

func Close()

func Const

func Const(i int) func() int

func Exit

func Exit()

func HandleEvent

func HandleEvent(event vaxis.Event)

func Initialize

func Initialize(content DrawableInteractive) error

func Invalidate

func Invalidate()

Invalidate marks the entire UI as invalid and request a redraw as soon as possible. Invalidate can be called from any goroutine and will never block.

func PadLeft

func PadLeft(ss *vaxis.StyledString, width int)

PadLeft inserts blank spaces at the beginning of the StyledString to produce a string of the provided width

func PadRight

func PadRight(ss *vaxis.StyledString, width int)

PadLeft inserts blank spaces at the end of the StyledString to produce a string of the provided width

func QueueFunc

func QueueFunc(fn func())

QueueFunc queues a function to be called in the main goroutine. This can be used to prevent race conditions from delayed functions

func QueueSuspend

func QueueSuspend()

func Render

func Render()

func StyledString

func StyledString(s string) *vaxis.StyledString

func Suspend

func Suspend() error

func Truncate

func Truncate(ss *vaxis.StyledString, width int)

Truncates the styled string on the right and inserts a '…' as the last character

func TruncateHead

func TruncateHead(ss *vaxis.StyledString, width int)

TruncateHead truncates the left side of the string and inserts '…' as the first character

Types

type Beeper

type Beeper interface {
	OnBeep(func())
}

type Bordered

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

func NewBordered

func NewBordered(
	content Drawable, borders uint, uiConfig *config.UIConfig,
) *Bordered

func (*Bordered) Children

func (bordered *Bordered) Children() []Drawable

func (*Bordered) Draw

func (bordered *Bordered) Draw(ctx *Context)

func (*Bordered) Invalidate

func (bordered *Bordered) Invalidate()

func (*Bordered) MouseEvent

func (bordered *Bordered) MouseEvent(localX int, localY int, event vaxis.Event)

type Box

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

func NewBox

func NewBox(
	content Drawable, title, borders string, uiConfig *config.UIConfig,
) *Box

func (*Box) Draw

func (b *Box) Draw(ctx *Context)

func (*Box) Event

func (b *Box) Event(e vaxis.Event) bool

func (*Box) Focus

func (b *Box) Focus(_ bool)

func (*Box) Invalidate

func (b *Box) Invalidate()

func (*Box) MouseEvent

func (b *Box) MouseEvent(localX int, localY int, event vaxis.Event)

type Closeable

type Closeable interface {
	Close()
}

type Column

type Column struct {
	Offset    int
	Width     int
	Def       *config.ColumnDef
	Separator string
}

type Container

type Container interface {
	Drawable
	// Return all of the drawables which are children of this one (do not
	// recurse into your grandchildren).
	Children() []Drawable
}

A drawable which contains other drawables

type Context

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

A context allows you to draw in a sub-region of the terminal

func NewContext

func NewContext(vx *vaxis.Vaxis, p func(*Popover)) *Context

func (*Context) Fill

func (ctx *Context) Fill(x, y, width, height int, rune rune, style vaxis.Style)

func (*Context) Height

func (ctx *Context) Height() int

func (*Context) HideCursor

func (ctx *Context) HideCursor()

func (*Context) Popover

func (ctx *Context) Popover(x, y, width, height int, d Drawable)

func (*Context) Printf

func (ctx *Context) Printf(x, y int, style vaxis.Style,
	format string, a ...interface{},
) int

func (*Context) SetCell

func (ctx *Context) SetCell(x, y int, ch rune, style vaxis.Style)

func (*Context) SetCursor

func (ctx *Context) SetCursor(x, y int, style vaxis.CursorStyle)

func (*Context) Size

func (ctx *Context) Size() (int, int)

func (*Context) Subcontext

func (ctx *Context) Subcontext(x, y, width, height int) *Context

func (*Context) Width

func (ctx *Context) Width() int

func (*Context) Window

func (ctx *Context) Window() vaxis.Window

returns the vaxis Window for this context

type Drawable

type Drawable interface {
	// Called when this renderable should draw itself.
	Draw(ctx *Context)
	// Invalidates the UI. This can be called from any goroutine.
	Invalidate()
}

Drawable is a UI component that can draw. Unless specified, all methods must only be called from a single goroutine, the UI goroutine.

type DrawableInteractive

type DrawableInteractive interface {
	Drawable
	Interactive
}

type DrawableInteractiveBeeper

type DrawableInteractiveBeeper interface {
	DrawableInteractive
	Beeper
}

type Fill

type Fill struct {
	Rune  rune
	Style vaxis.Style
}

func NewFill

func NewFill(f rune, s vaxis.Style) Fill

func (Fill) Draw

func (f Fill) Draw(ctx *Context)

func (Fill) Invalidate

func (f Fill) Invalidate()

type Grid

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

func MakeGrid

func MakeGrid(numRows, numCols, rowStrategy, colStrategy int) *Grid

MakeGrid creates a grid with the specified number of columns and rows. Each cell has a size of 1.

func NewGrid

func NewGrid() *Grid

func (*Grid) AddChild

func (grid *Grid) AddChild(content Drawable) *GridCell

func (*Grid) Columns

func (grid *Grid) Columns(spec []GridSpec) *Grid

func (*Grid) Draw

func (grid *Grid) Draw(ctx *Context)

func (*Grid) Invalidate

func (grid *Grid) Invalidate()

func (*Grid) MouseEvent

func (grid *Grid) MouseEvent(localX int, localY int, event vaxis.Event)

func (*Grid) RemoveChild

func (grid *Grid) RemoveChild(content Drawable)

func (*Grid) ReplaceChild

func (grid *Grid) ReplaceChild(old Drawable, new Drawable)

func (*Grid) Rows

func (grid *Grid) Rows(spec []GridSpec) *Grid

type GridCell

type GridCell struct {
	Row     int
	Column  int
	RowSpan int
	ColSpan int
	Content Drawable
}

func (*GridCell) At

func (cell *GridCell) At(row, col int) *GridCell

func (*GridCell) Span

func (cell *GridCell) Span(rows, cols int) *GridCell

type GridSpec

type GridSpec struct {
	// One of SIZE_EXACT or SIZE_WEIGHT
	Strategy int

	// If Strategy = SIZE_EXACT, this function returns the number of cells
	// this row/col shall occupy. If SIZE_WEIGHT, the space left after all
	// exact rows/cols are measured is distributed amonst the remainder
	// weighted by the value returned by this function.
	Size func() int
}

Specifies the layout of a single row or column

type Interactive

type Interactive interface {
	// Returns true if the event was handled by this component
	Event(event vaxis.Event) bool
	// Indicates whether or not this control will receive input events
	Focus(focus bool)
}

type MouseHandler

type MouseHandler interface {
	// Handle a mouse event which occurred at the local x and y positions
	MouseEvent(localX int, localY int, event vaxis.Event)
}

type Mouseable

type Mouseable interface {
	Drawable
	MouseHandler
}

A drawable that can be interacted with by the mouse

type MouseableDrawableInteractive

type MouseableDrawableInteractive interface {
	DrawableInteractive
	MouseHandler
}

type Popover

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

func (*Popover) Draw

func (p *Popover) Draw(ctx *Context)

func (*Popover) Event

func (p *Popover) Event(e vaxis.Event) bool

func (*Popover) Focus

func (p *Popover) Focus(f bool)

func (*Popover) Invalidate

func (p *Popover) Invalidate()

type Row

type Row struct {
	Cells []string
	Priv  interface{}
}

type Stack

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

func NewStack

func NewStack(uiConfig *config.UIConfig) *Stack

func (*Stack) Children

func (stack *Stack) Children() []Drawable

func (*Stack) Draw

func (stack *Stack) Draw(ctx *Context)

func (*Stack) Invalidate

func (stack *Stack) Invalidate()

func (*Stack) MouseEvent

func (stack *Stack) MouseEvent(localX int, localY int, event vaxis.Event)

func (*Stack) Peek

func (stack *Stack) Peek() Drawable

func (*Stack) Pop

func (stack *Stack) Pop() Drawable

func (*Stack) Push

func (stack *Stack) Push(d Drawable)

type Tab

type Tab struct {
	Content Drawable
	Name    string
	// contains filtered or unexported fields
}

func (*Tab) GetDisplayName

func (t *Tab) GetDisplayName() string

func (*Tab) SetTitle

func (t *Tab) SetTitle(s string)

type TabContent

type TabContent Tabs

func (*TabContent) Children

func (content *TabContent) Children() []Drawable

func (*TabContent) Draw

func (content *TabContent) Draw(ctx *Context)

func (*TabContent) Invalidate

func (content *TabContent) Invalidate()

func (*TabContent) MouseEvent

func (content *TabContent) MouseEvent(localX int, localY int, event vaxis.Event)

type TabStrip

type TabStrip Tabs

func (*TabStrip) Draw

func (strip *TabStrip) Draw(ctx *Context)

TODO: Color repository

func (*TabStrip) Invalidate

func (strip *TabStrip) Invalidate()

func (*TabStrip) MouseEvent

func (strip *TabStrip) MouseEvent(localX int, localY int, event vaxis.Event)

type Table

type Table struct {
	Columns []Column
	Rows    []Row
	Height  int
	// Optional callback that allows customizing the default drawing routine
	// of table rows. If true is returned, the default routine is skipped.
	CustomDraw func(t *Table, row int, c *Context) bool
	// Optional callback that allows returning a custom style for the row.
	GetRowStyle func(t *Table, row int) vaxis.Style
	// contains filtered or unexported fields
}

func NewTable

func NewTable(
	height int,
	columnDefs []*config.ColumnDef, separator string,
	customDraw func(*Table, int, *Context) bool,
	getRowStyle func(*Table, int) vaxis.Style,
) Table

func (*Table) AddRow

func (t *Table) AddRow(cells []string, priv interface{}) bool

add a row to the table, returns true when the table is full

func (*Table) Draw

func (t *Table) Draw(ctx *Context)

type Tabs

type Tabs struct {
	TabStrip   *TabStrip
	TabContent *TabContent

	CloseTab func(index int)
	// contains filtered or unexported fields
}

func NewTabs

func NewTabs(uiConf *config.UIConfig) *Tabs

func (*Tabs) Add

func (tabs *Tabs) Add(content Drawable, name string, uiConf *config.UIConfig) *Tab

func (*Tabs) Get

func (tabs *Tabs) Get(index int) *Tab

func (*Tabs) MoveTab

func (tabs *Tabs) MoveTab(to int, relative bool)

func (*Tabs) Names

func (tabs *Tabs) Names() []string

func (*Tabs) NextTab

func (tabs *Tabs) NextTab()

func (*Tabs) PinTab

func (tabs *Tabs) PinTab()

func (*Tabs) PrevTab

func (tabs *Tabs) PrevTab()

func (*Tabs) Remove

func (tabs *Tabs) Remove(content Drawable)

func (*Tabs) Replace

func (tabs *Tabs) Replace(contentSrc Drawable, contentTarget Drawable, name string)

func (*Tabs) Select

func (tabs *Tabs) Select(index int) bool

func (*Tabs) SelectName

func (tabs *Tabs) SelectName(name string) bool

func (*Tabs) SelectOffset

func (tabs *Tabs) SelectOffset(offset int)

func (*Tabs) SelectPrevious

func (tabs *Tabs) SelectPrevious() bool

func (*Tabs) Selected

func (tabs *Tabs) Selected() *Tab

func (*Tabs) UnpinTab

func (tabs *Tabs) UnpinTab()

type Text

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

func NewText

func NewText(text string, style vaxis.Style) *Text

func (*Text) Draw

func (t *Text) Draw(ctx *Context)

func (*Text) Invalidate

func (t *Text) Invalidate()

func (*Text) Strategy

func (t *Text) Strategy(strategy uint) *Text

func (*Text) Text

func (t *Text) Text(text string) *Text

type TextInput

type TextInput struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTextInput

func NewTextInput(text string, ui *config.UIConfig) *TextInput

Creates a new TextInput. TextInputs will render a "textbox" in the entire context they're given, and process keypresses to build a string from user input.

func (*TextInput) Draw

func (ti *TextInput) Draw(ctx *Context)

func (*TextInput) Event

func (ti *TextInput) Event(event vaxis.Event) bool

func (*TextInput) Focus

func (ti *TextInput) Focus(focus bool)

func (*TextInput) Invalidate

func (ti *TextInput) Invalidate()

func (*TextInput) MouseEvent

func (ti *TextInput) MouseEvent(localX int, localY int, event vaxis.Event)

func (*TextInput) OnChange

func (ti *TextInput) OnChange(onChange func(ti *TextInput))

func (*TextInput) OnFocusLost

func (ti *TextInput) OnFocusLost(onFocusLost func(ti *TextInput))

func (*TextInput) Password

func (ti *TextInput) Password(password bool) *TextInput

func (*TextInput) Prompt

func (ti *TextInput) Prompt(prompt string) *TextInput

func (*TextInput) Set

func (ti *TextInput) Set(value string) *TextInput

func (*TextInput) String

func (ti *TextInput) String() string

func (*TextInput) StringLeft

func (ti *TextInput) StringLeft() string

func (*TextInput) StringRight

func (ti *TextInput) StringRight() string

func (*TextInput) TabComplete

func (ti *TextInput) TabComplete(
	tabcomplete func(s string) ([]string, string),
	d time.Duration, minChars int, key *config.KeyStroke,
) *TextInput

type Visible

type Visible interface {
	// Indicate that this component is visible or not
	Show(bool)
}

Jump to

Keyboard shortcuts

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