ui

package
v0.0.0-...-b9af839 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 16 Imported by: 0

README

This lib was forked from aerc on october 10th 2021 from commit 0b19b5e70e408bbaac5555b0b61a9451189406f8. It has since diverged to be more in line with what this project needs

This file is here to aknowledge where this comes from and who the original author was.

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 StyleNames = map[string]StyleObject{
	"default": STYLE_DEFAULT,
	"error":   STYLE_ERROR,
	"warning": STYLE_WARNING,
	"success": STYLE_SUCCESS,

	"title":  STYLE_TITLE,
	"header": STYLE_HEADER,

	"statusline_default": STYLE_STATUSLINE_DEFAULT,
	"statusline_error":   STYLE_STATUSLINE_ERROR,
	"statusline_success": STYLE_STATUSLINE_SUCCESS,

	"msglist_default": STYLE_MSGLIST_DEFAULT,
	"msglist_unread":  STYLE_MSGLIST_UNREAD,
	"msglist_read":    STYLE_MSGLIST_READ,
	"msglist_flagged": STYLE_MSGLIST_FLAGGED,
	"msglist_deleted": STYLE_MSGLIST_DELETED,
	"msglist_marked":  STYLE_MSGLIST_MARKED,

	"dirlist_default": STYLE_DIRLIST_DEFAULT,

	"completion_default": STYLE_COMPLETION_DEFAULT,
	"completion_gutter":  STYLE_COMPLETION_GUTTER,
	"completion_pill":    STYLE_COMPLETION_PILL,

	"tab":     STYLE_TAB,
	"stack":   STYLE_STACK,
	"spinner": STYLE_SPINNER,
	"border":  STYLE_BORDER,

	"selector_default": STYLE_SELECTOR_DEFAULT,
	"selector_focused": STYLE_SELECTOR_FOCUSED,
	"selector_chooser": STYLE_SELECTOR_CHOOSER,
}

Functions

func Const

func Const(i int) func() int

Types

type Beeper

type Beeper interface {
	OnBeep(func() error)
}

type Bordered

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

func NewBordered

func NewBordered(
	content Drawable, borders uint, uiConfig 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 tcell.Event)

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(width, height int, screen tcell.Screen, p func(*Popover)) *Context

func (*Context) Fill

func (ctx *Context) Fill(x, y, width, height int, rune rune, style tcell.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 tcell.Style,
	format string, a ...interface{}) int

func (*Context) SetCell

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

func (*Context) SetCursor

func (ctx *Context) SetCursor(x, y int)

func (*Context) Subcontext

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

func (*Context) Width

func (ctx *Context) Width() int

func (*Context) X

func (ctx *Context) X() int

func (*Context) Y

func (ctx *Context) Y() int

type Drawable

type Drawable interface {
	// Called when this renderable should draw itself.
	Draw(ctx *Context)
	// Specifies a function to call when this cell needs to be redrawn. The
	// callback may be called in any goroutine.
	OnInvalidate(callback func(d Drawable))
	// Invalidates the drawable. 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 rune

func NewFill

func NewFill(f rune) Fill

func (Fill) Draw

func (f Fill) Draw(ctx *Context)

func (Fill) Invalidate

func (f Fill) Invalidate()

func (Fill) OnInvalidate

func (f Fill) OnInvalidate(callback func(d Drawable))

type Grid

type Grid struct {
	Invalidatable
	// 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) Children

func (grid *Grid) Children() []Drawable

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 tcell.Event)

func (*Grid) RemoveChild

func (grid *Grid) RemoveChild(content 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
	// contains filtered or unexported fields
}

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 tcell.Event) bool
	// Indicates whether or not this control will receive input events
	Focus(focus bool)
}

type Invalidatable

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

func (*Invalidatable) DoInvalidate

func (i *Invalidatable) DoInvalidate(d Drawable)

func (*Invalidatable) OnInvalidate

func (i *Invalidatable) OnInvalidate(f func(d Drawable))

type MouseHandler

type MouseHandler interface {
	// Handle a mouse event which occurred at the local x and y positions
	MouseEvent(localX int, localY int, event tcell.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 tcell.Event) bool

func (*Popover) Focus

func (p *Popover) Focus(f bool)

func (*Popover) Invalidate

func (p *Popover) Invalidate()

func (*Popover) OnInvalidate

func (p *Popover) OnInvalidate(f func(Drawable))

type RootDrawable

type RootDrawable interface {
	Initialize(ui *UI)
}

type Stack

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

func NewStack

func NewStack(uiConfig 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 tcell.Event)

func (*Stack) OnInvalidate

func (stack *Stack) OnInvalidate(onInvalidate func(d Drawable))

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 Style

type Style struct {
	Fg        tcell.Color
	Bg        tcell.Color
	Bold      bool
	Blink     bool
	Underline bool
	Reverse   bool
}

func (*Style) Default

func (s *Style) Default() *Style

func (Style) Get

func (s Style) Get() tcell.Style

func (*Style) Normal

func (s *Style) Normal()

func (*Style) Reset

func (s *Style) Reset() *Style

func (*Style) Set

func (s *Style) Set(attr, val string) error

type StyleObject

type StyleObject int32
const (
	STYLE_DEFAULT StyleObject = iota
	STYLE_ERROR
	STYLE_WARNING
	STYLE_SUCCESS

	STYLE_TITLE
	STYLE_HEADER

	STYLE_STATUSLINE_DEFAULT
	STYLE_STATUSLINE_ERROR
	STYLE_STATUSLINE_SUCCESS

	STYLE_MSGLIST_DEFAULT
	STYLE_MSGLIST_UNREAD
	STYLE_MSGLIST_READ
	STYLE_MSGLIST_FLAGGED
	STYLE_MSGLIST_DELETED
	STYLE_MSGLIST_MARKED

	STYLE_DIRLIST_DEFAULT

	STYLE_COMPLETION_DEFAULT
	STYLE_COMPLETION_GUTTER
	STYLE_COMPLETION_PILL

	STYLE_TAB
	STYLE_STACK
	STYLE_SPINNER
	STYLE_BORDER

	STYLE_SELECTOR_DEFAULT
	STYLE_SELECTOR_FOCUSED
	STYLE_SELECTOR_CHOOSER
)

type StyleSet

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

func NewStyleSet

func NewStyleSet() StyleSet

func (StyleSet) Compose

func (ss StyleSet) Compose(so StyleObject, sos []StyleObject) tcell.Style

func (StyleSet) ComposeSelected

func (ss StyleSet) ComposeSelected(so StyleObject,
	sos []StyleObject) tcell.Style

func (StyleSet) Get

func (ss StyleSet) Get(so StyleObject) tcell.Style

func (*StyleSet) LoadStyleSet

func (ss *StyleSet) LoadStyleSet(stylesetName string, stylesetDirs []string) error

func (*StyleSet) ParseStyleSet

func (ss *StyleSet) ParseStyleSet(file *ini.File) error

func (StyleSet) Selected

func (ss StyleSet) Selected(so StyleObject) tcell.Style

type Tab

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

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 tcell.Event)

func (*TabContent) OnInvalidate

func (content *TabContent) OnInvalidate(onInvalidate func(d Drawable))

type TabStrip

type TabStrip Tabs

func (*TabStrip) Clicked

func (strip *TabStrip) Clicked(mouseX int, mouseY int) (int, bool)

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 tcell.Event)

func (*TabStrip) OnInvalidate

func (strip *TabStrip) OnInvalidate(onInvalidate func(d Drawable))

type Tabs

type Tabs struct {
	Tabs       []*Tab
	TabStrip   *TabStrip
	TabContent *TabContent
	Selected   int

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

func NewTabs

func NewTabs(uiConf *UIConfig) *Tabs

func (*Tabs) Add

func (tabs *Tabs) Add(content Drawable, name string) *Tab

func (*Tabs) MoveTab

func (tabs *Tabs) MoveTab(to int)

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)

func (*Tabs) SelectPrevious

func (tabs *Tabs) SelectPrevious() bool

func (*Tabs) UnpinTab

func (tabs *Tabs) UnpinTab()

type Text

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

func NewText

func NewText(text string, style tcell.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 {
	Invalidatable
	// contains filtered or unexported fields
}

func NewTextInput

func NewTextInput(text string, ui 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 tcell.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 tcell.Event)

func (*TextInput) OnChange

func (ti *TextInput) OnChange(onChange 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, d time.Duration) *TextInput

type UI

type UI struct {
	Content DrawableInteractive
	// contains filtered or unexported fields
}

func Initialize

func Initialize(content DrawableInteractive) (*UI, error)

func (*UI) Close

func (state *UI) Close()

func (*UI) EnableMouse

func (state *UI) EnableMouse()

func (*UI) Exit

func (state *UI) Exit()

func (*UI) ShouldExit

func (state *UI) ShouldExit() bool

func (*UI) Tick

func (state *UI) Tick() bool

type UIConfig

type UIConfig struct {
	PinnedTabMarker string `ini:"pinned-tab-marker"`
	SidebarWidth    int    `ini:"sidebar-width"`
	PreviewHeight   int    `ini:"preview-height"`
	EmptyFeed       string `ini:"empty-feed"`
	MouseEnabled    bool   `ini:"mouse-enabled"`
	//NewArticleBell      bool          `ini:"new-article-bell"`
	Spinner          string `ini:"spinner"`
	SpinnerDelimiter string `ini:"spinner-delimiter"`
	//Sort                []string      `delim:" "`
	//CompletionDelay     time.Duration `ini:"completion-delay"`
	//CompletionPopovers  bool          `ini:"completion-popovers"`
	StyleSetDirs []string `ini:"stylesets-dirs" delim:":"`
	StyleSetName string   `ini:"styleset-name"`
	// contains filtered or unexported fields
}

TODO add back the removed stuff TODO some of this stuff should probably be extracted if it is not directly used in the lib

func (UIConfig) GetComposedStyle

func (uiConfig UIConfig) GetComposedStyle(base StyleObject,
	styles []StyleObject) tcell.Style

func (UIConfig) GetComposedStyleSelected

func (uiConfig UIConfig) GetComposedStyleSelected(base StyleObject, styles []StyleObject) tcell.Style

func (UIConfig) GetStyle

func (uiConfig UIConfig) GetStyle(so StyleObject) tcell.Style

func (UIConfig) GetStyleSelected

func (uiConfig UIConfig) GetStyleSelected(so StyleObject) tcell.Style

Jump to

Keyboard shortcuts

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