tui-go: github.com/marcusolsson/tui-go Index | Files | Directories

package tui

import "github.com/marcusolsson/tui-go"

Package tui is a library for building user interfaces for the terminal.

Widgets

Widgets are the main building blocks of any user interface. They allow us to present information and interact with our application. It receives keyboard and mouse events from the terminal and draws a representation of itself.

lbl := tui.NewLabel("Hello, World!")

Layouts

Widgets are structured using layouts. Layouts are powerful tools that let you position your widgets without having to specify their exact coordinates.

box := tui.NewVBox(
	tui.NewLabel("Press the button to continue ..."),
	tui.NewButton("Continue"),
)

Here, the VBox will ensure that the Button will be placed underneath the Label. There are currently three layouts to choose from; VBox, HBox and Grid.

Size policies

Sizing of widgets is controlled by its SizePolicy. For now, you can read more about how size policies work in the Qt docs:

http://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum

Index

Package Files

box.go button.go doc.go entry.go event.go focus.go grid.go keybinding.go label.go list.go padder.go painter.go progress.go runebuf.go scroll_area.go spacer.go statusbar.go table.go text.go text_edit.go theme.go ui.go ui_tcell.go widget.go

Constants

const (
    KeyBackspace  = KeyBS
    KeyTab        = KeyTAB
    KeyEsc        = KeyESC
    KeyEscape     = KeyESC
    KeyEnter      = KeyCR
    KeyBackspace2 = KeyDEL
)

These are aliases for other keys.

Variables

var DefaultFocusChain = &SimpleFocusChain{
    widgets: make([]Widget, 0),
}

DefaultFocusChain is the default focus chain.

var DefaultTheme = &Theme{
    styles: map[string]Style{
        "list.item.selected":  {Reverse: true},
        "table.cell.selected": {Reverse: true},
        "button.focused":      {Reverse: true},
        "box.focused":         {Reverse: true},
    },
}

DefaultTheme is a theme with reasonable defaults.

type Alignment Uses

type Alignment int

Alignment is used to set the direction in which widgets are laid out.

const (
    Horizontal Alignment = iota
    Vertical
)

Available alignment options.

type Box Uses

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

Box is a layout for placing widgets either horizontally or vertically. If horizontally, all widgets will have the same height. If vertically, they will all have the same width.

func NewHBox Uses

func NewHBox(c ...Widget) *Box

NewHBox returns a new horizontally aligned Box.

func NewVBox Uses

func NewVBox(c ...Widget) *Box

NewVBox returns a new vertically aligned Box.

func (*Box) Alignment Uses

func (b *Box) Alignment() Alignment

Alignment returns the current alignment of the Box.

func (*Box) Append Uses

func (b *Box) Append(w Widget)

Append adds the given widget at the end of the Box.

func (*Box) Draw Uses

func (b *Box) Draw(p *Painter)

Draw recursively draws the widgets it contains.

func (*Box) Insert Uses

func (b *Box) Insert(i int, w Widget)

Insert adds the widget into the Box at a given index.

func (*Box) IsFocused Uses

func (b *Box) IsFocused() bool

IsFocused return true if one of the children is focused.

func (*Box) MinSizeHint Uses

func (b *Box) MinSizeHint() image.Point

MinSizeHint returns the minimum size hint for the layout.

func (*Box) OnKeyEvent Uses

func (b *Box) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles an event and propagates it to all children.

func (*Box) Prepend Uses

func (b *Box) Prepend(w Widget)

Prepend adds the given widget at the start of the Box.

func (*Box) Remove Uses

func (b *Box) Remove(i int)

Remove deletes the widget from the Box at a given index.

func (*Box) Resize Uses

func (b *Box) Resize(size image.Point)

Resize recursively updates the size of the Box and all the widgets it contains. This is a potentially expensive operation and should be invoked with restraint.

Resize is called by the layout engine and is not intended to be used by end users.

func (*Box) SetBorder Uses

func (b *Box) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

func (*Box) SetTitle Uses

func (b *Box) SetTitle(title string)

SetTitle sets the title of the box.

func (*Box) SizeHint Uses

func (b *Box) SizeHint() image.Point

SizeHint returns the recommended size hint for the layout.

type Button Uses

type Button struct {
    WidgetBase
    // contains filtered or unexported fields
}

Button is a widget that can be activated to perform some action, or to answer a question.

func NewButton Uses

func NewButton(text string) *Button

NewButton returns a new Button with the given text as the label.

func (*Button) Draw Uses

func (b *Button) Draw(p *Painter)

Draw draws the button.

func (*Button) OnActivated Uses

func (b *Button) OnActivated(fn func(b *Button))

OnActivated allows a custom function to be run whenever the button is activated.

func (*Button) OnKeyEvent Uses

func (b *Button) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles keys events.

func (*Button) SizeHint Uses

func (b *Button) SizeHint() image.Point

SizeHint returns the recommended size hint for the button.

type Color Uses

type Color int

Color represents a color.

const (
    ColorDefault Color = iota
    ColorBlack
    ColorWhite
    ColorRed
    ColorGreen
    ColorBlue
    ColorCyan
    ColorMagenta
    ColorYellow
)

Common colors.

type Entry Uses

type Entry struct {
    WidgetBase
    // contains filtered or unexported fields
}

Entry is a one-line text editor. It lets the user supply the application with text, e.g., to input user and password information.

func NewEntry Uses

func NewEntry() *Entry

NewEntry returns a new Entry.

func (*Entry) Draw Uses

func (e *Entry) Draw(p *Painter)

Draw draws the entry.

func (*Entry) OnChanged Uses

func (e *Entry) OnChanged(fn func(entry *Entry))

OnChanged sets a function to be run whenever the content of the entry has been changed.

func (*Entry) OnKeyEvent Uses

func (e *Entry) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*Entry) OnSubmit Uses

func (e *Entry) OnSubmit(fn func(entry *Entry))

OnSubmit sets a function to be run whenever the user submits the entry (by pressing KeyEnter).

func (*Entry) SetText Uses

func (e *Entry) SetText(text string)

SetText sets the text content of the entry.

func (*Entry) SizeHint Uses

func (e *Entry) SizeHint() image.Point

SizeHint returns the recommended size hint for the entry.

func (*Entry) Text Uses

func (e *Entry) Text() string

Text returns the text content of the entry.

type FocusChain Uses

type FocusChain interface {
    FocusNext(w Widget) Widget
    FocusPrev(w Widget) Widget
    FocusDefault() Widget
}

FocusChain enables custom focus traversal when Tab or Backtab is pressed.

type Grid Uses

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

Grid is a widget that lays out widgets in a grid.

func NewGrid Uses

func NewGrid(cols, rows int) *Grid

NewGrid returns a new Grid.

func (*Grid) AppendRow Uses

func (g *Grid) AppendRow(row ...Widget)

AppendRow adds a new row at the end.

func (*Grid) Draw Uses

func (g *Grid) Draw(p *Painter)

Draw draws the grid.

func (*Grid) MinSizeHint Uses

func (g *Grid) MinSizeHint() image.Point

MinSizeHint returns the minimum size hint for the grid.

func (*Grid) OnKeyEvent Uses

func (g *Grid) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*Grid) RemoveRow Uses

func (g *Grid) RemoveRow(index int)

RemoveRow removes the row ( at index ) from the grid

func (*Grid) RemoveRows Uses

func (g *Grid) RemoveRows()

RemoveRows will remove all the rows in grid

func (*Grid) Resize Uses

func (g *Grid) Resize(size image.Point)

Resize recursively updates the size of the Grid and all the widgets it contains. This is a potentially expensive operation and should be invoked with restraint.

Resize is called by the layout engine and is not intended to be used by end users.

func (*Grid) SetBorder Uses

func (g *Grid) SetBorder(enabled bool)

SetBorder sets whether the border is visible or not.

func (*Grid) SetCell Uses

func (g *Grid) SetCell(pos image.Point, w Widget)

SetCell sets or replaces the contents of a cell.

func (*Grid) SetColumnStretch Uses

func (g *Grid) SetColumnStretch(col, stretch int)

SetColumnStretch sets the stretch factor for a given column. If stretch > 0, the column will expand to fill up available space. If multiple columns have a stretch factor > 0, stretch determines how much space the column get in respect to the others. E.g. by setting SetColumnStretch(0, 1) and SetColumnStretch(1, 2), the second column will fill up twice as much space as the first one.

func (*Grid) SetRowStretch Uses

func (g *Grid) SetRowStretch(row, stretch int)

SetRowStretch sets the stretch factor for a given row. For more on stretch factors, see SetColumnStretch.

func (*Grid) SizeHint Uses

func (g *Grid) SizeHint() image.Point

SizeHint returns the recommended size hint for the grid.

type Key Uses

type Key int16

Key represents both normal and special keys. For normal letters, KeyRune is used together with the Rune field in the KeyEvent.

const (
    KeyRune Key = iota + 256
    KeyUp
    KeyDown
    KeyRight
    KeyLeft
    KeyUpLeft
    KeyUpRight
    KeyDownLeft
    KeyDownRight
    KeyCenter
    KeyPgUp
    KeyPgDn
    KeyHome
    KeyEnd
    KeyInsert
    KeyDelete
    KeyHelp
    KeyExit
    KeyClear
    KeyCancel
    KeyPrint
    KeyPause
    KeyBacktab
    KeyF1
    KeyF2
    KeyF3
    KeyF4
    KeyF5
    KeyF6
    KeyF7
    KeyF8
    KeyF9
    KeyF10
    KeyF11
    KeyF12
    KeyF13
    KeyF14
    KeyF15
    KeyF16
    KeyF17
    KeyF18
    KeyF19
    KeyF20
    KeyF21
    KeyF22
    KeyF23
    KeyF24
    KeyF25
    KeyF26
    KeyF27
    KeyF28
    KeyF29
    KeyF30
    KeyF31
    KeyF32
    KeyF33
    KeyF34
    KeyF35
    KeyF36
    KeyF37
    KeyF38
    KeyF39
    KeyF40
    KeyF41
    KeyF42
    KeyF43
    KeyF44
    KeyF45
    KeyF46
    KeyF47
    KeyF48
    KeyF49
    KeyF50
    KeyF51
    KeyF52
    KeyF53
    KeyF54
    KeyF55
    KeyF56
    KeyF57
    KeyF58
    KeyF59
    KeyF60
    KeyF61
    KeyF62
    KeyF63
    KeyF64
)

These are named keys that can be handled.

const (
    KeyCtrlSpace Key = iota
    KeyCtrlA
    KeyCtrlB
    KeyCtrlC
    KeyCtrlD
    KeyCtrlE
    KeyCtrlF
    KeyCtrlG
    KeyCtrlH
    KeyCtrlI
    KeyCtrlJ
    KeyCtrlK
    KeyCtrlL
    KeyCtrlM
    KeyCtrlN
    KeyCtrlO
    KeyCtrlP
    KeyCtrlQ
    KeyCtrlR
    KeyCtrlS
    KeyCtrlT
    KeyCtrlU
    KeyCtrlV
    KeyCtrlW
    KeyCtrlX
    KeyCtrlY
    KeyCtrlZ
    KeyCtrlLeftSq // Escape
    KeyCtrlBackslash
    KeyCtrlRightSq
    KeyCtrlCarat
    KeyCtrlUnderscore
)

These are the supported control keys.

const (
    KeyNUL Key = iota
    KeySOH
    KeySTX
    KeyETX
    KeyEOT
    KeyENQ
    KeyACK
    KeyBEL
    KeyBS
    KeyTAB
    KeyLF
    KeyVT
    KeyFF
    KeyCR
    KeySO
    KeySI
    KeyDLE
    KeyDC1
    KeyDC2
    KeyDC3
    KeyDC4
    KeyNAK
    KeySYN
    KeyETB
    KeyCAN
    KeyEM
    KeySUB
    KeyESC
    KeyFS
    KeyGS
    KeyRS
    KeyUS
    KeyDEL Key = 0x7F
)

These are the defined ASCII values for key codes.

type KeyEvent Uses

type KeyEvent struct {
    Key       Key
    Rune      rune
    Modifiers ModMask
}

KeyEvent represents a key press.

func (*KeyEvent) Name Uses

func (ev *KeyEvent) Name() string

Name returns a user-friendly description of the key press.

type Label Uses

type Label struct {
    WidgetBase
    // contains filtered or unexported fields
}

Label is a widget to display read-only text.

func NewLabel Uses

func NewLabel(text string) *Label

NewLabel returns a new Label.

func (*Label) Draw Uses

func (l *Label) Draw(p *Painter)

Draw draws the label.

func (*Label) MinSizeHint Uses

func (l *Label) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Label) SetStyleName Uses

func (l *Label) SetStyleName(style string)

SetStyleName sets the identifier used for custom styling.

func (*Label) SetText Uses

func (l *Label) SetText(text string)

SetText sets the text content of the label.

func (*Label) SetWordWrap Uses

func (l *Label) SetWordWrap(enabled bool)

SetWordWrap sets whether text content should be wrapped.

func (*Label) SizeHint Uses

func (l *Label) SizeHint() image.Point

SizeHint returns the recommended size for the label.

func (*Label) Text Uses

func (l *Label) Text() string

Text returns the text content of the label.

type List Uses

type List struct {
    WidgetBase
    // contains filtered or unexported fields
}

List is a widget for displaying and selecting items.

func NewList Uses

func NewList() *List

NewList returns a new List with no selection.

func (*List) AddItems Uses

func (l *List) AddItems(items ...string)

AddItems appends items to the end of the list.

func (*List) Draw Uses

func (l *List) Draw(p *Painter)

Draw draws the list.

func (*List) Length Uses

func (l *List) Length() int

Length returns the number of items in the list.

func (*List) OnItemActivated Uses

func (l *List) OnItemActivated(fn func(*List))

OnItemActivated gets called when activated (through pressing KeyEnter).

func (*List) OnKeyEvent Uses

func (l *List) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles terminal events.

func (*List) OnSelectionChanged Uses

func (l *List) OnSelectionChanged(fn func(*List))

OnSelectionChanged gets called whenever a new item is selected.

func (*List) RemoveItem Uses

func (l *List) RemoveItem(i int)

RemoveItem removes the item at the given position.

func (*List) RemoveItems Uses

func (l *List) RemoveItems()

RemoveItems clears all the items from the list.

func (*List) Select Uses

func (l *List) Select(i int)

Select calls SetSelected and the OnSelectionChanged function.

func (*List) Selected Uses

func (l *List) Selected() int

Selected returns the index of the currently selected item.

func (*List) SelectedItem Uses

func (l *List) SelectedItem() string

SelectedItem returns the currently selected item.

func (*List) SetSelected Uses

func (l *List) SetSelected(i int)

SetSelected sets the currently selected item.

func (*List) SizeHint Uses

func (l *List) SizeHint() image.Point

SizeHint returns the recommended size for the list.

type ModMask Uses

type ModMask int16

ModMask is a mask of modifier keys.

const (
    ModShift ModMask = 1 << iota
    ModCtrl
    ModAlt
    ModMeta
    ModNone ModMask = 0
)

Modifiers that can be sent with a KeyEvent or a MouseEvent.

type MouseEvent Uses

type MouseEvent struct {
    Pos image.Point
}

MouseEvent represents the event where a mouse button was pressed or released.

type Padder Uses

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

Padder is a widget to fill out space.

func NewPadder Uses

func NewPadder(x, y int, w Widget) *Padder

NewPadder returns a new Padder.

func (*Padder) Draw Uses

func (p *Padder) Draw(painter *Painter)

Draw draws the padded widget.

func (*Padder) IsFocused Uses

func (p *Padder) IsFocused() bool

IsFocused returns true if the widget is focused.

func (*Padder) MinSizeHint Uses

func (p *Padder) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Padder) OnKeyEvent Uses

func (p *Padder) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*Padder) Resize Uses

func (p *Padder) Resize(size image.Point)

Resize updates the size of the padded widget.

func (*Padder) SetFocused Uses

func (p *Padder) SetFocused(f bool)

SetFocused set the focus on the widget.

func (*Padder) Size Uses

func (p *Padder) Size() image.Point

Size returns the size of the padded widget.

func (*Padder) SizeHint Uses

func (p *Padder) SizeHint() image.Point

SizeHint returns the recommended size for the padded widget.

func (*Padder) SizePolicy Uses

func (p *Padder) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type Painter Uses

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

Painter provides operations to paint on a surface.

func NewPainter Uses

func NewPainter(s Surface, p *Theme) *Painter

NewPainter returns a new instance of Painter.

func (*Painter) Begin Uses

func (p *Painter) Begin()

Begin prepares the surface for painting.

func (*Painter) DrawCursor Uses

func (p *Painter) DrawCursor(x, y int)

DrawCursor draws the cursor at the given position.

func (*Painter) DrawHorizontalLine Uses

func (p *Painter) DrawHorizontalLine(x1, x2, y int)

DrawHorizontalLine paints a horizontal line using box characters.

func (*Painter) DrawRect Uses

func (p *Painter) DrawRect(x, y, w, h int)

DrawRect paints a rectangle using box characters.

func (*Painter) DrawRune Uses

func (p *Painter) DrawRune(x, y int, r rune)

DrawRune paints a rune at the given coordinate.

func (*Painter) DrawText Uses

func (p *Painter) DrawText(x, y int, text string)

DrawText paints a string starting at the given coordinate.

func (*Painter) DrawVerticalLine Uses

func (p *Painter) DrawVerticalLine(x, y1, y2 int)

DrawVerticalLine paints a vertical line using box characters.

func (*Painter) End Uses

func (p *Painter) End()

End finalizes any painting that has been made.

func (*Painter) FillRect Uses

func (p *Painter) FillRect(x, y, w, h int)

FillRect clears a rectangular area with whitespace.

func (*Painter) Repaint Uses

func (p *Painter) Repaint(w Widget)

Repaint clears the surface, draws the scene and flushes it.

func (*Painter) Restore Uses

func (p *Painter) Restore()

Restore pops the latest transform from the stack.

func (*Painter) RestoreStyle Uses

func (p *Painter) RestoreStyle()

RestoreStyle clears any style and restores it to the default.

func (*Painter) SetStyle Uses

func (p *Painter) SetStyle(s Style)

SetStyle sets the style used when painting.

func (*Painter) Translate Uses

func (p *Painter) Translate(x, y int)

Translate pushes a new translation transform to the stack.

func (*Painter) WithMask Uses

func (p *Painter) WithMask(r image.Rectangle, fn func(*Painter))

WithMask masks a painter to restrict painting within the given rectangle.

func (*Painter) WithStyle Uses

func (p *Painter) WithStyle(n string, fn func(*Painter))

WithStyle decorates the painter with the style associated with an identifier.

type Progress Uses

type Progress struct {
    WidgetBase
    // contains filtered or unexported fields
}

Progress is a widget to display a progress bar.

func NewProgress Uses

func NewProgress(max int) *Progress

NewProgress returns a new Progress.

func (*Progress) Draw Uses

func (p *Progress) Draw(painter *Painter)

Draw draws the progress bar.

func (*Progress) MinSizeHint Uses

func (p *Progress) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Progress) SetCurrent Uses

func (p *Progress) SetCurrent(c int)

SetCurrent sets the current progress.

func (*Progress) SetMax Uses

func (p *Progress) SetMax(m int)

SetMax sets the maximum progress.

func (*Progress) SizeHint Uses

func (p *Progress) SizeHint() image.Point

SizeHint returns the recommended size for the progress bar.

type RuneBuffer Uses

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

RuneBuffer provides readline functionality for text widgets.

func (*RuneBuffer) Backspace Uses

func (r *RuneBuffer) Backspace()

Backspace deletes the rune left of the cursor.

func (*RuneBuffer) CursorPos Uses

func (r *RuneBuffer) CursorPos() image.Point

CursorPos returns the coordinate for the cursor for a given width.

func (*RuneBuffer) Delete Uses

func (r *RuneBuffer) Delete()

Delete deletes the rune at the current cursor position.

func (*RuneBuffer) Kill Uses

func (r *RuneBuffer) Kill()

Kill deletes all runes from the cursor until the end of the line.

func (*RuneBuffer) Len Uses

func (r *RuneBuffer) Len() int

Len returns the number of runes in the buffer.

func (*RuneBuffer) MoveBackward Uses

func (r *RuneBuffer) MoveBackward()

MoveBackward moves the cursor back by one rune.

func (*RuneBuffer) MoveForward Uses

func (r *RuneBuffer) MoveForward()

MoveForward moves the cursor forward by one rune.

func (*RuneBuffer) MoveToLineEnd Uses

func (r *RuneBuffer) MoveToLineEnd()

MoveToLineEnd moves the cursor to the end of the current line.

func (*RuneBuffer) MoveToLineStart Uses

func (r *RuneBuffer) MoveToLineStart()

MoveToLineStart moves the cursor to the start of the current line.

func (*RuneBuffer) Pos Uses

func (r *RuneBuffer) Pos() int

Pos returns the current index in the buffer.

func (*RuneBuffer) Set Uses

func (r *RuneBuffer) Set(buf []rune)

Set the buffer and the index at the end of the buffer.

func (*RuneBuffer) SetMaxWidth Uses

func (r *RuneBuffer) SetMaxWidth(w int)

SetMaxWidth sets the maximum text width.

func (*RuneBuffer) SetWithIdx Uses

func (r *RuneBuffer) SetWithIdx(idx int, buf []rune)

SetWithIdx set the the buffer with a given index.

func (*RuneBuffer) SplitByLine Uses

func (r *RuneBuffer) SplitByLine() []string

SplitByLine returns the lines for a given width.

func (*RuneBuffer) String Uses

func (r *RuneBuffer) String() string

func (*RuneBuffer) Width Uses

func (r *RuneBuffer) Width() int

Width returns the width of the rune buffer, taking into account for CJK.

func (*RuneBuffer) WriteRune Uses

func (r *RuneBuffer) WriteRune(s rune)

WriteRune appends a rune to the buffer.

func (*RuneBuffer) WriteRunes Uses

func (r *RuneBuffer) WriteRunes(s []rune)

WriteRunes appends runes to the buffer.

type ScrollArea Uses

type ScrollArea struct {
    WidgetBase

    Widget Widget
    // contains filtered or unexported fields
}

ScrollArea is a widget to fill out space.

func NewScrollArea Uses

func NewScrollArea(w Widget) *ScrollArea

NewScrollArea returns a new ScrollArea.

func (*ScrollArea) Draw Uses

func (s *ScrollArea) Draw(p *Painter)

Draw draws the scroll area.

func (*ScrollArea) MinSizeHint Uses

func (s *ScrollArea) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*ScrollArea) Resize Uses

func (s *ScrollArea) Resize(size image.Point)

Resize resizes the scroll area and the underlying widget.

func (*ScrollArea) Scroll Uses

func (s *ScrollArea) Scroll(dx, dy int)

Scroll shifts the views over the content.

func (*ScrollArea) SizeHint Uses

func (s *ScrollArea) SizeHint() image.Point

SizeHint returns the size hint of the underlying widget.

func (*ScrollArea) SizePolicy Uses

func (s *ScrollArea) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type SimpleFocusChain Uses

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

SimpleFocusChain represents a ring of widgets where focus is loops to the first widget when it reaches the end.

func (*SimpleFocusChain) FocusDefault Uses

func (c *SimpleFocusChain) FocusDefault() Widget

FocusDefault returns the default widget for when there is no widget currently focused.

func (*SimpleFocusChain) FocusNext Uses

func (c *SimpleFocusChain) FocusNext(current Widget) Widget

FocusNext returns the widget in the ring that is after the given widget.

func (*SimpleFocusChain) FocusPrev Uses

func (c *SimpleFocusChain) FocusPrev(current Widget) Widget

FocusPrev returns the widget in the ring that is before the given widget.

func (*SimpleFocusChain) Set Uses

func (c *SimpleFocusChain) Set(ws ...Widget)

Set sets the widgets in the focus chain. Widgets will received focus in the order widgets were passed.

type SizePolicy Uses

type SizePolicy int

SizePolicy determines the space occupied by a widget.

const (
    // Preferred interprets the size hint as the preferred size.
    Preferred SizePolicy = iota
    // Minimum allows the widget to shrink down to the size hint.
    Minimum
    // Maximum allows the widget to grow up to the size hint.
    Maximum
    // Expanding makes the widget expand to the available space.
    Expanding
)

type Spacer Uses

type Spacer struct {
    WidgetBase
}

Spacer is a widget to fill out space.

func NewSpacer Uses

func NewSpacer() *Spacer

NewSpacer returns a new Spacer.

func (*Spacer) MinSizeHint Uses

func (s *Spacer) MinSizeHint() image.Point

MinSizeHint returns the minimum size the widget is allowed to be.

func (*Spacer) SizeHint Uses

func (s *Spacer) SizeHint() image.Point

SizeHint returns the recommended size for the spacer.

func (*Spacer) SizePolicy Uses

func (s *Spacer) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type StatusBar Uses

type StatusBar struct {
    WidgetBase
    // contains filtered or unexported fields
}

StatusBar is a widget to display status information.

func NewStatusBar Uses

func NewStatusBar(text string) *StatusBar

NewStatusBar returns a new StatusBar.

func (*StatusBar) Draw Uses

func (b *StatusBar) Draw(p *Painter)

Draw draws the status bar.

func (*StatusBar) SetPermanentText Uses

func (b *StatusBar) SetPermanentText(text string)

SetPermanentText sets the permanent text of the status bar.

func (*StatusBar) SetText Uses

func (b *StatusBar) SetText(text string)

SetText sets the text content of the status bar.

func (*StatusBar) SizeHint Uses

func (b *StatusBar) SizeHint() image.Point

SizeHint returns the recommended size for the status bar.

func (*StatusBar) SizePolicy Uses

func (b *StatusBar) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the default layout behavior.

type Style Uses

type Style struct {
    Fg      Color
    Bg      Color
    Reverse bool

    Bold      bool
    Underline bool
}

Style determines how a cell should be painted.

type Surface Uses

type Surface interface {
    SetCell(x, y int, ch rune, s Style)
    SetCursor(x, y int)
    HideCursor()
    Begin()
    End()
    Size() image.Point
}

Surface defines a surface that can be painted on.

type Table Uses

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

Table is a widget that lays out widgets in a table.

func NewTable Uses

func NewTable(cols, rows int) *Table

NewTable returns a new Table.

func (*Table) Draw Uses

func (t *Table) Draw(p *Painter)

Draw draws the table.

func (*Table) OnItemActivated Uses

func (t *Table) OnItemActivated(fn func(*Table))

OnItemActivated sets the function that is called when an item was activated.

func (*Table) OnKeyEvent Uses

func (t *Table) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles an event and propagates it to all children.

func (*Table) OnSelectionChanged Uses

func (t *Table) OnSelectionChanged(fn func(*Table))

OnSelectionChanged sets the function that is called when an item was selected.

func (*Table) RemoveRow Uses

func (t *Table) RemoveRow(index int)

RemoveRow removes specific row from the table

func (*Table) RemoveRows Uses

func (t *Table) RemoveRows()

RemoveRows removes all the rows added to the table.

func (*Table) Select Uses

func (t *Table) Select(i int)

Select calls SetSelected and the OnSelectionChanged function.

func (*Table) Selected Uses

func (t *Table) Selected() int

Selected returns the index of the currently selected item.

func (*Table) SetSelected Uses

func (t *Table) SetSelected(i int)

SetSelected changes the currently selected item.

type TextEdit Uses

type TextEdit struct {
    WidgetBase
    // contains filtered or unexported fields
}

TextEdit is a multi-line text editor.

func NewTextEdit Uses

func NewTextEdit() *TextEdit

NewTextEdit returns a new TextEdit.

func (*TextEdit) Draw Uses

func (e *TextEdit) Draw(p *Painter)

Draw draws the entry.

func (*TextEdit) OnKeyEvent Uses

func (e *TextEdit) OnKeyEvent(ev KeyEvent)

OnKeyEvent handles key events.

func (*TextEdit) OnTextChanged Uses

func (e *TextEdit) OnTextChanged(fn func(entry *TextEdit))

OnTextChanged sets a function to be run whenever the text content of the widget has been changed.

func (*TextEdit) SetText Uses

func (e *TextEdit) SetText(text string)

SetText sets the text content of the entry.

func (*TextEdit) SetWordWrap Uses

func (e *TextEdit) SetWordWrap(enabled bool)

SetWordWrap sets whether the text should wrap or not.

func (*TextEdit) SizeHint Uses

func (e *TextEdit) SizeHint() image.Point

SizeHint returns the recommended size for the entry.

func (*TextEdit) Text Uses

func (e *TextEdit) Text() string

Text returns the text content of the entry.

type Theme Uses

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

Theme defines the styles for a set of identifiers.

func NewTheme Uses

func NewTheme() *Theme

NewTheme return an empty theme.

func (*Theme) HasStyle Uses

func (p *Theme) HasStyle(name string) bool

HasStyle returns whether an identifier is associated with an identifier.

func (*Theme) SetStyle Uses

func (p *Theme) SetStyle(n string, i Style)

SetStyle sets a style for a given identifier.

func (*Theme) Style Uses

func (p *Theme) Style(name string) Style

Style returns the style associated with an identifier.

type UI Uses

type UI interface {
    SetWidget(w Widget)
    SetTheme(p *Theme)
    SetKeybinding(seq string, fn func())
    SetFocusChain(ch FocusChain)
    Run() error
    Update(fn func())
    Quit()
}

UI defines the operations needed by the underlying engine.

func New Uses

func New(root Widget) UI

New returns a new UI with a root widget.

type Widget Uses

type Widget interface {
    Draw(p *Painter)
    MinSizeHint() image.Point
    Size() image.Point
    SizeHint() image.Point
    SizePolicy() (SizePolicy, SizePolicy)
    Resize(size image.Point)
    OnKeyEvent(ev KeyEvent)
    SetFocused(bool)
    IsFocused() bool
}

Widget defines common operations on widgets.

type WidgetBase Uses

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

WidgetBase defines base attributes and operations for all widgets.

func (*WidgetBase) Draw Uses

func (w *WidgetBase) Draw(p *Painter)

Draw is an empty operation to fulfill the Widget interface.

func (*WidgetBase) IsFocused Uses

func (w *WidgetBase) IsFocused() bool

IsFocused returns whether the widget is focused.

func (*WidgetBase) MinSizeHint Uses

func (w *WidgetBase) MinSizeHint() image.Point

MinSizeHint returns the size below which the widget cannot shrink.

func (*WidgetBase) OnKeyEvent Uses

func (w *WidgetBase) OnKeyEvent(ev KeyEvent)

OnKeyEvent is an empty operation to fulfill the Widget interface.

func (*WidgetBase) Resize Uses

func (w *WidgetBase) Resize(size image.Point)

Resize sets the size of the widget.

func (*WidgetBase) SetFocused Uses

func (w *WidgetBase) SetFocused(f bool)

SetFocused focuses the widget.

func (*WidgetBase) SetSizePolicy Uses

func (w *WidgetBase) SetSizePolicy(h, v SizePolicy)

SetSizePolicy sets the size policy for horizontal and vertical directions.

func (*WidgetBase) Size Uses

func (w *WidgetBase) Size() image.Point

Size returns the current size of the widget.

func (*WidgetBase) SizeHint Uses

func (w *WidgetBase) SizeHint() image.Point

SizeHint returns the size hint of the widget.

func (*WidgetBase) SizePolicy Uses

func (w *WidgetBase) SizePolicy() (SizePolicy, SizePolicy)

SizePolicy returns the current size policy.

Directories

PathSynopsis
wordwrap

Package tui imports 9 packages (graph) and is imported by 3 packages. Updated 2017-11-18. Refresh now. Tools for package owners.