termui: github.com/gizak/termui/v3 Index | Files | Directories

package termui

import "github.com/gizak/termui/v3"

Package termui is a library for creating terminal user interfaces (TUIs) using widgets.

Index

Package Files

alignment.go backend.go block.go buffer.go canvas.go doc.go events.go grid.go render.go style.go style_parser.go symbols.go symbols_other.go theme.go utils.go

Constants

const (
    DOT      = '•'
    ELLIPSES = '…'

    UP_ARROW   = '▲'
    DOWN_ARROW = '▼'

    COLLAPSED = '+'
    EXPANDED  = '−'
)
const (
    TOP_LEFT     = '┌'
    TOP_RIGHT    = '┐'
    BOTTOM_LEFT  = '└'
    BOTTOM_RIGHT = '┘'

    VERTICAL_LINE   = '│'
    HORIZONTAL_LINE = '─'

    VERTICAL_LEFT   = '┤'
    VERTICAL_RIGHT  = '├'
    HORIZONTAL_UP   = '┴'
    HORIZONTAL_DOWN = '┬'

    QUOTA_LEFT  = '«'
    QUOTA_RIGHT = '»'

    VERTICAL_DASH   = '┊'
    HORIZONTAL_DASH = '┈'
)

Variables

var (
    BARS = [...]rune{' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}

    SHADED_BLOCKS = [...]rune{' ', '░', '▒', '▓', '█'}

    IRREGULAR_BLOCKS = [...]rune{
        ' ', '▘', '▝', '▀', '▖', '▌', '▞', '▛',
        '▗', '▚', '▐', '▜', '▄', '▙', '▟', '█',
    }

    BRAILLE_OFFSET = '\u2800'
    BRAILLE        = [4][2]rune{
        {'\u0001', '\u0008'},
        {'\u0002', '\u0010'},
        {'\u0004', '\u0020'},
        {'\u0040', '\u0080'},
    }

    DOUBLE_BRAILLE = map[[2]int]rune{
        [2]int{0, 0}: '⣀',
        [2]int{0, 1}: '⡠',
        [2]int{0, 2}: '⡐',
        [2]int{0, 3}: '⡈',

        [2]int{1, 0}: '⢄',
        [2]int{1, 1}: '⠤',
        [2]int{1, 2}: '⠔',
        [2]int{1, 3}: '⠌',

        [2]int{2, 0}: '⢂',
        [2]int{2, 1}: '⠢',
        [2]int{2, 2}: '⠒',
        [2]int{2, 3}: '⠊',

        [2]int{3, 0}: '⢁',
        [2]int{3, 1}: '⠡',
        [2]int{3, 2}: '⠑',
        [2]int{3, 3}: '⠉',
    }

    SINGLE_BRAILLE_LEFT  = [4]rune{'\u2840', '⠄', '⠂', '⠁'}
    SINGLE_BRAILLE_RIGHT = [4]rune{'\u2880', '⠠', '⠐', '⠈'}
)
var CellClear = Cell{
    Rune:  ' ',
    Style: StyleClear,
}
var StandardColors = []Color{
    ColorRed,
    ColorGreen,
    ColorYellow,
    ColorBlue,
    ColorMagenta,
    ColorCyan,
    ColorWhite,
}
var StandardStyles = []Style{
    NewStyle(ColorRed),
    NewStyle(ColorGreen),
    NewStyle(ColorYellow),
    NewStyle(ColorBlue),
    NewStyle(ColorMagenta),
    NewStyle(ColorCyan),
    NewStyle(ColorWhite),
}
var StyleClear = Style{
    Fg:       ColorClear,
    Bg:       ColorClear,
    Modifier: ModifierClear,
}

StyleClear represents a default Style, with no colors or modifiers

var StyleParserColorMap = map[string]Color{
    "red":     ColorRed,
    "blue":    ColorBlue,
    "black":   ColorBlack,
    "cyan":    ColorCyan,
    "yellow":  ColorYellow,
    "white":   ColorWhite,
    "clear":   ColorClear,
    "green":   ColorGreen,
    "magenta": ColorMagenta,
}

StyleParserColorMap can be modified to add custom color parsing to text

var Theme = RootTheme{
    Default: NewStyle(ColorWhite),

    Block: BlockTheme{
        Title:  NewStyle(ColorWhite),
        Border: NewStyle(ColorWhite),
    },

    BarChart: BarChartTheme{
        Bars:   StandardColors,
        Nums:   StandardStyles,
        Labels: StandardStyles,
    },

    Paragraph: ParagraphTheme{
        Text: NewStyle(ColorWhite),
    },

    PieChart: PieChartTheme{
        Slices: StandardColors,
    },

    List: ListTheme{
        Text: NewStyle(ColorWhite),
    },

    Tree: TreeTheme{
        Text:      NewStyle(ColorWhite),
        Collapsed: COLLAPSED,
        Expanded:  EXPANDED,
    },

    StackedBarChart: StackedBarChartTheme{
        Bars:   StandardColors,
        Nums:   StandardStyles,
        Labels: StandardStyles,
    },

    Gauge: GaugeTheme{
        Bar:   ColorWhite,
        Label: NewStyle(ColorWhite),
    },

    Sparkline: SparklineTheme{
        Title: NewStyle(ColorWhite),
        Line:  ColorWhite,
    },

    Plot: PlotTheme{
        Lines: StandardColors,
        Axes:  ColorWhite,
    },

    Table: TableTheme{
        Text: NewStyle(ColorWhite),
    },

    Tab: TabTheme{
        Active:   NewStyle(ColorRed),
        Inactive: NewStyle(ColorWhite),
    },
}

Theme holds the default Styles and Colors for all widgets. You can set default widget Styles by modifying the Theme before creating the widgets.

func AbsInt Uses

func AbsInt(x int) int

func CellsToString Uses

func CellsToString(cells []Cell) string

func Clear Uses

func Clear()

func Close Uses

func Close()

Close closes termbox-go.

func FloorFloat64 Uses

func FloorFloat64(x float64) float64

func GetMaxFloat64From2dSlice Uses

func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error)

func GetMaxFloat64FromSlice Uses

func GetMaxFloat64FromSlice(slice []float64) (float64, error)

func GetMaxIntFromSlice Uses

func GetMaxIntFromSlice(slice []int) (int, error)

func Init Uses

func Init() error

Init initializes termbox-go and is required to render anything. After initialization, the library must be finalized with `Close`.

func InterfaceSlice Uses

func InterfaceSlice(slice interface{}) []interface{}

InterfaceSlice takes an []interface{} represented as an interface{} and converts it https://stackoverflow.com/questions/12753805/type-converting-slices-of-interfaces-in-go

func MaxFloat64 Uses

func MaxFloat64(x, y float64) float64

func MaxInt Uses

func MaxInt(x, y int) int

func MinFloat64 Uses

func MinFloat64(x, y float64) float64

func MinInt Uses

func MinInt(x, y int) int

func PollEvents Uses

func PollEvents() <-chan Event

PollEvents gets events from termbox, converts them, then sends them to each of its channels.

func Render Uses

func Render(items ...Drawable)

func RoundFloat64 Uses

func RoundFloat64(x float64) float64

func SplitCells Uses

func SplitCells(cells []Cell, r rune) [][]Cell

func SumFloat64Slice Uses

func SumFloat64Slice(data []float64) float64

func SumIntSlice Uses

func SumIntSlice(slice []int) int

func TerminalDimensions Uses

func TerminalDimensions() (int, int)

func TrimString Uses

func TrimString(s string, w int) string

TrimString trims a string to a max length and adds '…' to the end if it was trimmed.

type Alignment Uses

type Alignment uint
const (
    AlignLeft Alignment = iota
    AlignCenter
    AlignRight
)

type BarChartTheme Uses

type BarChartTheme struct {
    Bars   []Color
    Nums   []Style
    Labels []Style
}

type Block Uses

type Block struct {
    Border      bool
    BorderStyle Style

    BorderLeft, BorderRight, BorderTop, BorderBottom bool

    PaddingLeft, PaddingRight, PaddingTop, PaddingBottom int

    image.Rectangle
    Inner image.Rectangle

    Title      string
    TitleStyle Style

    sync.Mutex
}

Block is the base struct inherited by most widgets. Block manages size, position, border, and title. It implements all 3 of the methods needed for the `Drawable` interface. Custom widgets will override the Draw method.

func NewBlock Uses

func NewBlock() *Block

func (*Block) Draw Uses

func (self *Block) Draw(buf *Buffer)

Draw implements the Drawable interface.

func (*Block) GetRect Uses

func (self *Block) GetRect() image.Rectangle

GetRect implements the Drawable interface.

func (*Block) SetRect Uses

func (self *Block) SetRect(x1, y1, x2, y2 int)

SetRect implements the Drawable interface.

type BlockTheme Uses

type BlockTheme struct {
    Title  Style
    Border Style
}

type Buffer Uses

type Buffer struct {
    image.Rectangle
    CellMap map[image.Point]Cell
}

Buffer represents a section of a terminal and is a renderable rectangle of cells.

func NewBuffer Uses

func NewBuffer(r image.Rectangle) *Buffer

func (*Buffer) Fill Uses

func (self *Buffer) Fill(c Cell, rect image.Rectangle)

func (*Buffer) GetCell Uses

func (self *Buffer) GetCell(p image.Point) Cell

func (*Buffer) SetCell Uses

func (self *Buffer) SetCell(c Cell, p image.Point)

func (*Buffer) SetString Uses

func (self *Buffer) SetString(s string, style Style, p image.Point)

type Canvas Uses

type Canvas struct {
    Block
    drawille.Canvas
}

func NewCanvas Uses

func NewCanvas() *Canvas

func (*Canvas) Draw Uses

func (self *Canvas) Draw(buf *Buffer)

func (*Canvas) SetLine Uses

func (self *Canvas) SetLine(p0, p1 image.Point, color Color)

func (*Canvas) SetPoint Uses

func (self *Canvas) SetPoint(p image.Point, color Color)

type Cell Uses

type Cell struct {
    Rune  rune
    Style Style
}

Cell represents a viewable terminal cell

func NewCell Uses

func NewCell(rune rune, args ...interface{}) Cell

NewCell takes 1 to 2 arguments 1st argument = rune 2nd argument = optional style

func ParseStyles Uses

func ParseStyles(s string, defaultStyle Style) []Cell

ParseStyles parses a string for embedded Styles and returns []Cell with the correct styling. Uses defaultStyle for any text without an embedded style. Syntax is of the form [text](fg:<color>,mod:<attribute>,bg:<color>). Ordering does not matter. All fields are optional.

func RunesToStyledCells Uses

func RunesToStyledCells(runes []rune, style Style) []Cell

func TrimCells Uses

func TrimCells(cells []Cell, w int) []Cell

func WrapCells Uses

func WrapCells(cells []Cell, width uint) []Cell

WrapCells takes []Cell and inserts Cells containing '\n' wherever a linebreak should go.

type CellWithX Uses

type CellWithX struct {
    X    int
    Cell Cell
}

func BuildCellWithXArray Uses

func BuildCellWithXArray(cells []Cell) []CellWithX

type Color Uses

type Color int

Color is an integer from -1 to 255 -1 = ColorClear 0-255 = Xterm colors

const (
    ColorBlack   Color = 0
    ColorRed     Color = 1
    ColorGreen   Color = 2
    ColorYellow  Color = 3
    ColorBlue    Color = 4
    ColorMagenta Color = 5
    ColorCyan    Color = 6
    ColorWhite   Color = 7
)

Basic terminal colors

const ColorClear Color = -1

ColorClear clears the Fg or Bg color of a Style

func SelectColor Uses

func SelectColor(colors []Color, index int) Color

type Drawable Uses

type Drawable interface {
    GetRect() image.Rectangle
    SetRect(int, int, int, int)
    Draw(*Buffer)
    sync.Locker
}

type Event Uses

type Event struct {
    Type    EventType
    ID      string
    Payload interface{}
}

type EventType Uses

type EventType uint
const (
    KeyboardEvent EventType = iota
    MouseEvent
    ResizeEvent
)

type GaugeTheme Uses

type GaugeTheme struct {
    Bar   Color
    Label Style
}

type Grid Uses

type Grid struct {
    Block
    Items []*GridItem
}

func NewGrid Uses

func NewGrid() *Grid

func (*Grid) Draw Uses

func (self *Grid) Draw(buf *Buffer)

func (*Grid) Set Uses

func (self *Grid) Set(entries ...interface{})

Set is used to add Columns and Rows to the grid. It recursively searches the GridItems, adding leaves to the grid and calculating the dimensions of the leaves.

type GridItem Uses

type GridItem struct {
    Type        gridItemType
    XRatio      float64
    YRatio      float64
    WidthRatio  float64
    HeightRatio float64
    Entry       interface{} // Entry.type == GridBufferer if IsLeaf else []GridItem
    IsLeaf      bool
    // contains filtered or unexported fields
}

GridItem represents either a Row or Column in a grid. Holds sizing information and either an []GridItems or a widget.

func NewCol Uses

func NewCol(ratio float64, i ...interface{}) GridItem

NewCol takes a height percentage and either a widget or a Row or Column

func NewRow Uses

func NewRow(ratio float64, i ...interface{}) GridItem

NewRow takes a width percentage and either a widget or a Row or Column

type ListTheme Uses

type ListTheme struct {
    Text Style
}

type Modifier Uses

type Modifier uint
const (
    // ModifierClear clears any modifiers
    ModifierClear     Modifier = 0
    ModifierBold      Modifier = 1 << 9
    ModifierUnderline Modifier = 1 << 10
    ModifierReverse   Modifier = 1 << 11
)

type Mouse Uses

type Mouse struct {
    Drag bool
    X    int
    Y    int
}

Mouse payload.

type ParagraphTheme Uses

type ParagraphTheme struct {
    Text Style
}

type PieChartTheme Uses

type PieChartTheme struct {
    Slices []Color
}

type PlotTheme Uses

type PlotTheme struct {
    Lines []Color
    Axes  Color
}

type Resize Uses

type Resize struct {
    Width  int
    Height int
}

Resize payload.

type RootTheme Uses

type RootTheme struct {
    Default Style

    Block BlockTheme

    BarChart        BarChartTheme
    Gauge           GaugeTheme
    Plot            PlotTheme
    List            ListTheme
    Tree            TreeTheme
    Paragraph       ParagraphTheme
    PieChart        PieChartTheme
    Sparkline       SparklineTheme
    StackedBarChart StackedBarChartTheme
    Tab             TabTheme
    Table           TableTheme
}

type SparklineTheme Uses

type SparklineTheme struct {
    Title Style
    Line  Color
}

type StackedBarChartTheme Uses

type StackedBarChartTheme struct {
    Bars   []Color
    Nums   []Style
    Labels []Style
}

type Style Uses

type Style struct {
    Fg       Color
    Bg       Color
    Modifier Modifier
}

Style represents the style of one terminal cell

func NewStyle Uses

func NewStyle(fg Color, args ...interface{}) Style

NewStyle takes 1 to 3 arguments 1st argument = Fg 2nd argument = optional Bg 3rd argument = optional Modifier

func SelectStyle Uses

func SelectStyle(styles []Style, index int) Style

type TabTheme Uses

type TabTheme struct {
    Active   Style
    Inactive Style
}

type TableTheme Uses

type TableTheme struct {
    Text Style
}

type TreeTheme Uses

type TreeTheme struct {
    Text      Style
    Collapsed rune
    Expanded  rune
}

Directories

PathSynopsis
drawille
widgets

Package termui imports 10 packages (graph) and is imported by 43 packages. Updated 2019-07-15. Refresh now. Tools for package owners.