termui

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2016 License: GPL-3.0, MIT Imports: 11 Imported by: 0

README

termui Build Status Doc Status

termui is a cross-platform, easy-to-compile, and fully-customizable terminal dashboard. It is inspired by blessed-contrib, but purely in Go.

Now version v2 has arrived! It brings new event system, new theme system, new Buffer interface and specific colour text rendering. (some docs are missing, but it will be completed soon!)

Installation

master mirrors v2 branch, to install:

go get -u github.com/gizak/termui

For the compatible reason, you can choose to install the legacy version of termui:

go get gopkg.in/gizak/termui.v1

Usage

Layout

To use termui, the very first thing you may want to know is how to manage layout. termui offers two ways of doing this, known as absolute layout and grid layout.

Absolute layout

Each widget has an underlying block structure which basically is a box model. It has border, label and padding properties. A border of a widget can be chosen to hide or display (with its border label), you can pick a different front/back colour for the border as well. To display such a widget at a specific location in terminal window, you need to assign .X, .Y, .Height, .Width values for each widget before send it to .Render. Let's demonstrate these by a code snippet:

	import ui "github.com/gizak/termui" // <- ui shortcut, optional

	func main() {
		err := ui.Init()
		if err != nil {
			panic(err)
		}
		defer ui.Close()

		p := ui.NewPar(":PRESS q TO QUIT DEMO")
		p.Height = 3
		p.Width = 50
		p.TextFgColor = ui.ColorWhite
		p.BorderLabel = "Text Box"
		p.BorderFg = ui.ColorCyan

		g := ui.NewGauge()
		g.Percent = 50
		g.Width = 50
		g.Height = 3
		g.Y = 11
		g.BorderLabel = "Gauge"
		g.BarColor = ui.ColorRed
		g.BorderFg = ui.ColorWhite
		g.BorderLabelFg = ui.ColorCyan

		ui.Render(p, g) // feel free to call Render, it's async and non-block

		// event handler...
	}

Note that components can be overlapped (I'd rather call this a feature...), Render(rs ...Renderer) renders its args from left to right (i.e. each component's weight is arising from left to right).

Grid layout:

grid

Grid layout uses 12 columns grid system with expressive syntax. To use Grid, all we need to do is build a widget tree consisting of Rows and Cols (Actually a Col is also a Row but with a widget endpoint attached).

	import ui "github.com/gizak/termui"
	// init and create widgets...

	// build
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(6, 0, widget0),
			ui.NewCol(6, 0, widget1)),
		ui.NewRow(
			ui.NewCol(3, 0, widget2),
			ui.NewCol(3, 0, widget30, widget31, widget32),
			ui.NewCol(6, 0, widget4)))

	// calculate layout
	ui.Body.Align()

	ui.Render(ui.Body)
Events

termui ships with a http-like event mux handling system. All events are channeled up from different sources (typing, click, windows resize, custom event) and then encoded as universal Event object. Event.Path indicates the event type and Event.Data stores the event data struct. Add a handler to a certain event is easy as below:

	// handle key q pressing
	ui.Handle("/sys/kbd/q", func(ui.Event) {
		// press q to quit
		ui.StopLoop()
	})

	ui.Handle("/sys/kbd/C-x", func(ui.Event) {
		// handle Ctrl + x combination
	})

	ui.Handle("/sys/kbd", func(ui.Event) {
		// handle all other key pressing
	})

	// handle a 1s timer
	ui.Handle("/timer/1s", func(e ui.Event) {
		t := e.Data.(ui.EvtTimer)
		// t is a EvtTimer
		if t.Count%2 ==0 {
			// do something
		}
	})

	ui.Loop() // block until StopLoop is called
Widgets

Click image to see the corresponding demo codes.

par list gauge linechart barchart barchart sparklines

GoDoc

godoc

TODO

  • Grid layout
  • Event system
  • Canvas widget
  • Refine APIs
  • Focusable widgets

Changelog

License

This library is under the MIT License

Documentation

Overview

Package termui is a library designed for creating command line UI. For more info, goto http://github.com/gizak/termui

A simplest example:

package main

import ui "github.com/gizak/termui"

func main() {
    if err:=ui.Init(); err != nil {
        panic(err)
    }
    defer ui.Close()

    g := ui.NewGauge()
    g.Percent = 50
    g.Width = 50
    g.Border.Label = "Gauge"

    ui.Render(g)
}

Index

Constants

View Source
const BOTTOM_LEFT = '└'
View Source
const BOTTOM_RIGHT = '┘'
View Source
const HDASH = '┈'
View Source
const HORIZONTAL_DOWN = '┬'
View Source
const HORIZONTAL_LINE = '─'
View Source
const HORIZONTAL_UP = '┴'
View Source
const NumberofColors = 8

Have a constant that defines number of colors

View Source
const ORIGIN = '└'
View Source
const QUOTA_LEFT = '«'
View Source
const QUOTA_RIGHT = '»'
View Source
const TOP_LEFT = '┌'
View Source
const TOP_RIGHT = '┐'
View Source
const VDASH = '┊'
View Source
const VERTICAL_LEFT = '┤'
View Source
const VERTICAL_LINE = '│'
View Source
const VERTICAL_RIGHT = '├'

Variables

View Source
var ColorMap = map[string]Attribute{
	"fg":           ColorWhite,
	"bg":           ColorDefault,
	"border.fg":    ColorWhite,
	"label.fg":     ColorGreen,
	"par.fg":       ColorYellow,
	"par.label.bg": ColorWhite,
}
View Source
var DefaultEvtStream = NewEvtStream()
View Source
var DefaultTxBuilder = NewMarkdownTxBuilder()

DefaultTxBuilder is set to be MarkdownTxBuilder.

View Source
var DefualtHandler = func(e Event) {
}

Functions

func AlignArea added in v1.4.0

func AlignArea(parent, child image.Rectangle, a Align) image.Rectangle

func Clear added in v1.4.0

func Clear()

func ClearArea added in v1.4.0

func ClearArea(r image.Rectangle, bg Attribute)

func Close

func Close()

Close finalizes termui library, should be called after successful initialization when termui's functionality isn't required anymore.

func GenId added in v1.4.0

func GenId() string

func Handle added in v1.4.0

func Handle(path string, handler func(Event))

func Init

func Init() error

Init initializes termui library. This function should be called before any others. After initialization, the library must be finalized by 'Close' function.

func Loop added in v1.4.0

func Loop()

func Merge added in v1.4.0

func Merge(name string, ec chan Event)

func MoveArea added in v1.4.0

func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle

func NewSysEvtCh added in v1.4.0

func NewSysEvtCh() chan Event

func NewTimerCh added in v1.4.0

func NewTimerCh(du time.Duration) chan Event

func Render

func Render(bs ...Bufferer)

func SendCustomEvt added in v1.4.0

func SendCustomEvt(path string, data interface{})

func StopLoop added in v1.4.0

func StopLoop()

func TermHeight

func TermHeight() int

TermHeight returns the current terminal's height.

func TermRect added in v1.4.0

func TermRect() image.Rectangle

func TermWidth

func TermWidth() int

TermWidth returns the current terminal's width.

func TrimStr2Runes added in v1.4.0

func TrimStr2Runes(s string, w int) []rune

TrimStr2Runes trims string to w[-1 rune], appends …, and returns the runes of that string if string is grather then n. If string is small then w, return the runes.

func TrimStrIfAppropriate added in v1.4.0

func TrimStrIfAppropriate(s string, w int) string

TrimStrIfAppropriate trim string to "s[:-1] + …" if string > width otherwise return string

Types

type Align

type Align uint

Align is the position of the gauge's label.

const (
	AlignNone Align = 0
	AlignLeft Align = 1 << iota
	AlignRight
	AlignBottom
	AlignTop
	AlignCenterVertical
	AlignCenterHorizontal
	AlignCenter = AlignCenterVertical | AlignCenterHorizontal
)

All supported positions.

type Attribute

type Attribute uint16

Attribute is printable cell's color and style.

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

8 basic clolrs

const (
	AttrBold Attribute = 1 << (iota + 9)
	AttrUnderline
	AttrReverse
)

Text style

const ColorUndef Attribute = Attribute(^uint16(0))

func ColorRGB added in v1.4.0

func ColorRGB(r, g, b int) Attribute

0<=r,g,b <= 5

func StringToAttribute added in v1.4.0

func StringToAttribute(text string) Attribute

StringToAttribute converts text to a termui attribute. You may specifiy more then one attribute like that: "BLACK, BOLD, ...". All whitespaces are ignored.

func ThemeAttr added in v1.4.0

func ThemeAttr(name string) Attribute

type BarChart

type BarChart struct {
	Block
	BarColor   Attribute
	TextColor  Attribute
	NumColor   Attribute
	Data       []int
	DataLabels []string
	BarWidth   int
	BarGap     int
	// contains filtered or unexported fields
}

BarChart creates multiple bars in a widget:

bc := termui.NewBarChart()
data := []int{3, 2, 5, 3, 9, 5}
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
bc.Border.Label = "Bar Chart"
bc.Data = data
bc.Width = 26
bc.Height = 10
bc.DataLabels = bclabels
bc.TextColor = termui.ColorGreen
bc.BarColor = termui.ColorRed
bc.NumColor = termui.ColorYellow

func NewBarChart

func NewBarChart() *BarChart

NewBarChart returns a new *BarChart with current theme.

func (*BarChart) Buffer

func (bc *BarChart) Buffer() Buffer

Buffer implements Bufferer interface.

func (*BarChart) SetMax

func (bc *BarChart) SetMax(max int)

type Block

type Block struct {
	X             int
	Y             int
	Border        bool
	BorderFg      Attribute
	BorderBg      Attribute
	BorderLeft    bool
	BorderRight   bool
	BorderTop     bool
	BorderBottom  bool
	BorderLabel   string
	BorderLabelFg Attribute
	BorderLabelBg Attribute
	Display       bool
	Bg            Attribute
	Width         int
	Height        int
	PaddingTop    int
	PaddingBottom int
	PaddingLeft   int
	PaddingRight  int

	Float Align
	// contains filtered or unexported fields
}

Block is a base struct for all other upper level widgets, consider it as css: display:block. Normally you do not need to create it manually.

func NewBlock

func NewBlock() *Block

NewBlock returns a *Block which inherits styles from current theme.

func (*Block) Align added in v1.4.0

func (b *Block) Align()

Align computes box model

func (*Block) Buffer

func (b *Block) Buffer() Buffer

Buffer implements Bufferer interface. Draw background and border (if any).

func (Block) GetHeight

func (b Block) GetHeight() int

GetHeight implements GridBufferer. It returns current height of the block.

func (*Block) Handle added in v1.4.0

func (b *Block) Handle(path string, handler func(Event))

func (Block) Id added in v1.4.0

func (b Block) Id() string

func (*Block) InnerBounds

func (b *Block) InnerBounds() image.Rectangle

InnerBounds returns the internal bounds of the block after aligning and calculating the padding and border, if any.

func (Block) InnerHeight added in v1.4.0

func (b Block) InnerHeight() int

func (Block) InnerWidth added in v1.4.0

func (b Block) InnerWidth() int

func (Block) InnerX added in v1.4.0

func (b Block) InnerX() int

func (Block) InnerY added in v1.4.0

func (b Block) InnerY() int

func (*Block) SetWidth

func (b *Block) SetWidth(w int)

SetWidth implements GridBuffer interface, it sets block's width.

func (*Block) SetX

func (b *Block) SetX(x int)

SetX implements GridBufferer interface, which sets block's x position.

func (*Block) SetY

func (b *Block) SetY(y int)

SetY implements GridBufferer interface, it sets y position for block.

type Buffer added in v1.4.0

type Buffer struct {
	Area    image.Rectangle // selected drawing area
	CellMap map[image.Point]Cell
}

Buffer is a renderable rectangle cell data container.

func NewBuffer added in v1.4.0

func NewBuffer() Buffer

NewBuffer returns a new Buffer

func NewFilledBuffer added in v1.4.0

func NewFilledBuffer(x0, y0, x1, y1 int, ch rune, fg, bg Attribute) Buffer

NewFilledBuffer returns a new Buffer filled with ch, fb and bg.

func (Buffer) At added in v1.4.0

func (b Buffer) At(x, y int) Cell

At returns the cell at (x,y).

func (Buffer) Bounds added in v1.4.0

func (b Buffer) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color.

func (Buffer) Fill added in v1.4.0

func (b Buffer) Fill(ch rune, fg, bg Attribute)

Fill fills the Buffer b with ch,fg and bg.

func (*Buffer) Merge added in v1.4.0

func (b *Buffer) Merge(bs ...Buffer)

Merge merges bs Buffers onto b

func (Buffer) Set added in v1.4.0

func (b Buffer) Set(x, y int, c Cell)

Set assigns a char to (x,y)

func (*Buffer) SetArea added in v1.4.0

func (b *Buffer) SetArea(r image.Rectangle)

SetArea assigns a new rect area to Buffer b.

func (Buffer) Sync added in v1.4.0

func (b Buffer) Sync()

Sync sets drawing area to the buffer's bound

type Bufferer

type Bufferer interface {
	Buffer() Buffer
}

Bufferer should be implemented by all renderable components.

type Canvas

type Canvas map[[2]int]rune

Canvas contains drawing map: i,j -> rune

func NewCanvas

func NewCanvas() Canvas

NewCanvas returns an empty Canvas

func (Canvas) Buffer

func (c Canvas) Buffer() Buffer

Buffer returns un-styled points

func (Canvas) Set

func (c Canvas) Set(x, y int)

Set sets a point (x,y) in the virtual coordinate

func (Canvas) Unset

func (c Canvas) Unset(x, y int)

Unset removes point (x,y)

type Cell added in v1.4.0

type Cell struct {
	Ch rune
	Fg Attribute
	Bg Attribute
}

Cell is a rune with assigned Fg and Bg

func DTrimTxCls added in v1.4.0

func DTrimTxCls(cs []Cell, w int) []Cell

DTrimTxCls trims the overflowed text cells sequence and append dots at the end.

func NewCell added in v1.4.0

func NewCell(ch rune, fg, bg Attribute) Cell

NewCell returns a new cell

func TextCells added in v1.4.0

func TextCells(s string, fg, bg Attribute) []Cell

TextCells returns a coloured text cells []Cell

func TrimTxCells added in v1.4.0

func TrimTxCells(cs []Cell, w int) []Cell

TrimTxCells trims the overflowed text cells sequence.

func (Cell) Copy added in v1.4.0

func (c Cell) Copy() Cell

Copy return a copy of c

func (Cell) Width added in v1.4.0

func (c Cell) Width() int

Width returns the actual screen space the cell takes (usually 1 or 2).

type Event

type Event struct {
	Type string
	Path string
	From string
	To   string
	Data interface{}
	Time int64
}

type EvtErr added in v1.4.0

type EvtErr error

type EvtKbd added in v1.4.0

type EvtKbd struct {
	KeyStr string
}

type EvtMouse added in v1.4.0

type EvtMouse struct {
	X     int
	Y     int
	Press string
}

type EvtStream added in v1.4.0

type EvtStream struct {
	sync.RWMutex

	Handlers map[string]func(Event)
	// contains filtered or unexported fields
}

func NewEvtStream added in v1.4.0

func NewEvtStream() *EvtStream

func (*EvtStream) Handle added in v1.4.0

func (es *EvtStream) Handle(path string, handler func(Event))

func (*EvtStream) Hook added in v1.4.0

func (es *EvtStream) Hook(f func(Event))

func (*EvtStream) Init added in v1.4.0

func (es *EvtStream) Init()

func (*EvtStream) Loop added in v1.4.0

func (es *EvtStream) Loop()

func (*EvtStream) Merge added in v1.4.0

func (es *EvtStream) Merge(name string, ec chan Event)

func (*EvtStream) StopLoop added in v1.4.0

func (es *EvtStream) StopLoop()

type EvtTimer added in v1.4.0

type EvtTimer struct {
	Duration time.Duration
	Count    uint64
}

type EvtWnd added in v1.4.0

type EvtWnd struct {
	Width  int
	Height int
}

type Gauge

type Gauge struct {
	Block
	Percent                 int
	BarColor                Attribute
	PercentColor            Attribute
	PercentColorHighlighted Attribute
	Label                   string
	LabelAlign              Align
}

func NewGauge

func NewGauge() *Gauge

NewGauge return a new gauge with current theme.

func (*Gauge) Buffer

func (g *Gauge) Buffer() Buffer

Buffer implements Bufferer interface.

type Grid

type Grid struct {
	Rows    []*Row
	Width   int
	X       int
	Y       int
	BgColor Attribute
}

Grid implements 12 columns system. A simple example:

import ui "github.com/gizak/termui"
// init and create widgets...

// build
ui.Body.AddRows(
    ui.NewRow(
        ui.NewCol(6, 0, widget0),
        ui.NewCol(6, 0, widget1)),
    ui.NewRow(
        ui.NewCol(3, 0, widget2),
        ui.NewCol(3, 0, widget30, widget31, widget32),
        ui.NewCol(6, 0, widget4)))

// calculate layout
ui.Body.Align()

ui.Render(ui.Body)
var Body *Grid

func NewGrid

func NewGrid(rows ...*Row) *Grid

NewGrid returns *Grid with given rows.

func (*Grid) AddRows

func (g *Grid) AddRows(rs ...*Row)

AddRows appends given rows to Grid.

func (*Grid) Align

func (g *Grid) Align()

Align calculate each rows' layout.

func (Grid) Buffer

func (g Grid) Buffer() Buffer

Buffer implments Bufferer interface.

type GridBufferer

type GridBufferer interface {
	Bufferer
	GetHeight() int
	SetWidth(int)
	SetX(int)
	SetY(int)
}

GridBufferer introduces a Bufferer that can be manipulated by Grid.

type Hline added in v1.4.0

type Hline struct {
	X   int
	Y   int
	Len int
	Fg  Attribute
	Bg  Attribute
}

Hline is a horizontal line.

func (Hline) Buffer added in v1.4.0

func (l Hline) Buffer() Buffer

Buffer draws a horizontal line.

type LineChart

type LineChart struct {
	Block
	Data       []float64
	DataLabels []string // if unset, the data indices will be used
	Mode       string   // braille | dot
	DotStyle   rune
	LineColor  Attribute

	AxesColor Attribute
	// contains filtered or unexported fields
}

LineChart has two modes: braille(default) and dot. Using braille gives 2x capicity as dot mode, because one braille char can represent two data points.

lc := termui.NewLineChart()
lc.Border.Label = "braille-mode Line Chart"
lc.Data = [1.2, 1.3, 1.5, 1.7, 1.5, 1.6, 1.8, 2.0]
lc.Width = 50
lc.Height = 12
lc.AxesColor = termui.ColorWhite
lc.LineColor = termui.ColorGreen | termui.AttrBold
// termui.Render(lc)...

func NewLineChart

func NewLineChart() *LineChart

NewLineChart returns a new LineChart with current theme.

func (*LineChart) Buffer

func (lc *LineChart) Buffer() Buffer

Buffer implements Bufferer interface.

type List

type List struct {
	Block
	Items       []string
	Overflow    string
	ItemFgColor Attribute
	ItemBgColor Attribute
}

List displays []string as its items, it has a Overflow option (default is "hidden"), when set to "hidden", the item exceeding List's width is truncated, but when set to "wrap", the overflowed text breaks into next line.

  strs := []string{
		"[0] github.com/gizak/termui",
		"[1] editbox.go",
		"[2] iterrupt.go",
		"[3] keyboard.go",
		"[4] output.go",
		"[5] random_out.go",
		"[6] dashboard.go",
		"[7] nsf/termbox-go"}

  ls := termui.NewList()
  ls.Items = strs
  ls.ItemFgColor = termui.ColorYellow
  ls.Border.Label = "List"
  ls.Height = 7
  ls.Width = 25
  ls.Y = 0

func NewList

func NewList() *List

NewList returns a new *List with current theme.

func (*List) Buffer

func (l *List) Buffer() Buffer

Buffer implements Bufferer interface.

type MBarChart

type MBarChart struct {
	Block
	BarColor   [NumberofColors]Attribute
	TextColor  Attribute
	NumColor   [NumberofColors]Attribute
	Data       [NumberofColors][]int
	DataLabels []string
	BarWidth   int
	BarGap     int

	ShowScale bool
	// contains filtered or unexported fields
}

This is the implemetation of multi-colored or stacked bar graph. This is different from default barGraph which is implemented in bar.go Multi-Colored-BarChart creates multiple bars in a widget:

bc := termui.NewMBarChart()
data := make([][]int, 2)
data[0] := []int{3, 2, 5, 7, 9, 4}
data[1] := []int{7, 8, 5, 3, 1, 6}
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
bc.Border.Label = "Bar Chart"
bc.Data = data
bc.Width = 26
bc.Height = 10
bc.DataLabels = bclabels
bc.TextColor = termui.ColorGreen
bc.BarColor = termui.ColorRed
bc.NumColor = termui.ColorYellow

func NewMBarChart

func NewMBarChart() *MBarChart

NewBarChart returns a new *BarChart with current theme.

func (*MBarChart) Buffer

func (bc *MBarChart) Buffer() Buffer

Buffer implements Bufferer interface.

func (*MBarChart) SetMax

func (bc *MBarChart) SetMax(max int)

type MarkdownTxBuilder added in v1.4.0

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

MarkdownTxBuilder implements TextBuilder interface, using markdown syntax.

func (MarkdownTxBuilder) Build added in v1.4.0

func (mtb MarkdownTxBuilder) Build(s string, fg, bg Attribute) []Cell

Build implements TextBuilder interface.

type Par

type Par struct {
	Block
	Text        string
	TextFgColor Attribute
	TextBgColor Attribute
}

Par displays a paragraph.

par := termui.NewPar("Simple Text")
par.Height = 3
par.Width = 17
par.Border.Label = "Label"

func NewPar

func NewPar(s string) *Par

NewPar returns a new *Par with given text as its content.

func (*Par) Buffer

func (p *Par) Buffer() Buffer

Buffer implements Bufferer interface.

type Row

type Row struct {
	Cols   []*Row       //children
	Widget GridBufferer // root
	X      int
	Y      int
	Width  int
	Height int
	Span   int
	Offset int
}

Row builds a layout tree

func NewCol

func NewCol(span, offset int, widgets ...GridBufferer) *Row

NewCol accepts: widgets are LayoutBufferer or widgets is A NewRow. Note that if multiple widgets are provided, they will stack up in the col.

func NewRow

func NewRow(cols ...*Row) *Row

NewRow creates a new row out of given columns.

func (*Row) Buffer

func (r *Row) Buffer() Buffer

Buffer implements Bufferer interface, recursively merge all widgets buffer

func (Row) GetHeight

func (r Row) GetHeight() int

GetHeight implements GridBufferer interface.

func (*Row) SetWidth

func (r *Row) SetWidth(w int)

SetWidth implements GridBufferer interface.

func (*Row) SetX

func (r *Row) SetX(x int)

SetX implements GridBufferer interface.

func (*Row) SetY

func (r *Row) SetY(y int)

SetY implements GridBufferer interface.

type Sparkline

type Sparkline struct {
	Data       []int
	Height     int
	Title      string
	TitleColor Attribute
	LineColor  Attribute
	// contains filtered or unexported fields
}

Sparkline is like: ▅▆▂▂▅▇▂▂▃▆▆▆▅▃. The data points should be non-negative integers.

data := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1}
spl := termui.NewSparkline()
spl.Data = data
spl.Title = "Sparkline 0"
spl.LineColor = termui.ColorGreen

func NewSparkline

func NewSparkline() Sparkline

NewSparkline returns a unrenderable single sparkline that intended to be added into Sparklines.

type Sparklines

type Sparklines struct {
	Block
	Lines []Sparkline
	// contains filtered or unexported fields
}

Sparklines is a renderable widget which groups together the given sparklines.

spls := termui.NewSparklines(spl0,spl1,spl2) //...
spls.Height = 2
spls.Width = 20

func NewSparklines

func NewSparklines(ss ...Sparkline) *Sparklines

NewSparklines return a new *Spaklines with given Sparkline(s), you can always add a new Sparkline later.

func (*Sparklines) Add

func (s *Sparklines) Add(sl Sparkline)

Add appends a given Sparkline to s *Sparklines.

func (*Sparklines) Buffer

func (sl *Sparklines) Buffer() Buffer

Buffer implements Bufferer interface.

type TextBuilder added in v1.4.0

type TextBuilder interface {
	Build(s string, fg, bg Attribute) []Cell
}

TextBuilder is a minial interface to produce text []Cell using sepcific syntax (markdown).

func NewMarkdownTxBuilder added in v1.4.0

func NewMarkdownTxBuilder() TextBuilder

NewMarkdownTxBuilder returns a TextBuilder employing markdown syntax.

type Vline added in v1.4.0

type Vline struct {
	X   int
	Y   int
	Len int
	Fg  Attribute
	Bg  Attribute
}

Vline is a vertical line.

func (Vline) Buffer added in v1.4.0

func (l Vline) Buffer() Buffer

Buffer draws a vertical line.

type WgtInfo added in v1.4.0

type WgtInfo struct {
	Handlers map[string]func(Event)
	WgtRef   Widget
	Id       string
}

func NewWgtInfo added in v1.4.0

func NewWgtInfo(wgt Widget) WgtInfo

type WgtMgr added in v1.4.0

type WgtMgr map[string]WgtInfo

event mixins

var DefaultWgtMgr WgtMgr

func NewWgtMgr added in v1.4.0

func NewWgtMgr() WgtMgr

func (WgtMgr) AddWgt added in v1.4.0

func (wm WgtMgr) AddWgt(wgt Widget)

func (WgtMgr) AddWgtHandler added in v1.4.0

func (wm WgtMgr) AddWgtHandler(id, path string, h func(Event))

func (WgtMgr) RmWgt added in v1.4.0

func (wm WgtMgr) RmWgt(wgt Widget)

func (WgtMgr) RmWgtById added in v1.4.0

func (wm WgtMgr) RmWgtById(id string)

func (WgtMgr) RmWgtHandler added in v1.4.0

func (wm WgtMgr) RmWgtHandler(id, path string)

func (WgtMgr) WgtHandlersHook added in v1.4.0

func (wm WgtMgr) WgtHandlersHook() func(Event)

type Widget added in v1.4.0

type Widget interface {
	Id() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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