Documentation ¶
Overview ¶
Package termui is a library for creating terminal user interfaces (TUIs) using widgets.
Index ¶
- Constants
- Variables
- func AddColorMap(str string, attr Attribute)
- func AlignArea(parent, child image.Rectangle, a Align) image.Rectangle
- func CellsToStr(cs []Cell) string
- func Clear()
- func ClearArea(r image.Rectangle, bg Attribute)
- func Close()
- func GenId() string
- func Init() error
- func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle
- func PollEvents() <-chan Event
- func Render(bs ...Bufferer)
- func SetOutputMode(mode OutputMode)
- func TermHeight() int
- func TermRect() image.Rectangle
- func TermWidth() int
- func TrimStr2Runes(s string, w int) []rune
- func TrimStrIfAppropriate(s string, w int) string
- type Align
- type Attribute
- type BarChart
- type Block
- func (b *Block) Align()
- func (b *Block) Buffer() Buffer
- func (b Block) GetHeight() int
- func (b *Block) Handle(path string, handler func(Event))
- func (b Block) Id() string
- func (b *Block) InnerBounds() image.Rectangle
- func (b Block) InnerHeight() int
- func (b Block) InnerWidth() int
- func (b Block) InnerX() int
- func (b Block) InnerY() int
- func (b *Block) SetWidth(w int)
- func (b *Block) SetX(x int)
- func (b *Block) SetY(y int)
- type Buffer
- type Bufferer
- type Canvas
- type Cell
- type Event
- type EventType
- type Gauge
- type Grid
- type GridBufferer
- type Hline
- type LineChart
- type List
- type MarkdownTxBuilder
- type Mouse
- type OutputMode
- type Paragraph
- type PieChart
- type PieChartLabel
- type Resize
- type Row
- type Sparkline
- type Sparklines
- type StackedBarChart
- type Tab
- type TabPane
- type Table
- type TextBuilder
- type Vline
- type WgtInfo
- type WgtMgr
- type Widget
Constants ¶
const BOTTOM_LEFT = '└'
const BOTTOM_RIGHT = '┘'
const HDASH = '┈'
const HORIZONTAL_DOWN = '┬'
const HORIZONTAL_LINE = '─'
const HORIZONTAL_UP = '┴'
const NumberofColors = 8
Have a constant that defines number of colors
const ORIGIN = '└'
const QUOTA_LEFT = '«'
const QUOTA_RIGHT = '»'
const TOP_LEFT = '┌'
const TOP_RIGHT = '┐'
const VDASH = '┊'
const VERTICAL_LEFT = '┤'
const VERTICAL_LINE = '│'
const VERTICAL_RIGHT = '├'
Variables ¶
var ColorMap = map[string]Attribute{ "fg": ColorWhite, "bg": ColorDefault, "border.fg": ColorWhite, "label.fg": ColorGreen, "par.fg": ColorYellow, "par.label.bg": ColorWhite, }
var DefaultTxBuilder = NewMarkdownTxBuilder()
DefaultTxBuilder is set to be MarkdownTxBuilder.
Functions ¶
func AddColorMap ¶
Allow users to add/override the string to attribute mapping
func CellsToStr ¶
func Close ¶
func Close()
Close finalizes termui library, should be called after successful initialization when termui's functionality isn't required anymore.
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 PollEvents ¶
func PollEvents() <-chan Event
PollEvents gets events from termbox, converts them, then sends them to each of its channels.
func SetOutputMode ¶
func SetOutputMode(mode OutputMode)
Passthrough to termbox using termbox constants above
func TrimStr2Runes ¶
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 ¶
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
func ColorRGB24 ¶
Convert from familiar 24 bit colors into 6 bit terminal colors
func StringToAttribute ¶
StringToAttribute converts text to a termui attribute. You may specify more then one attribute like that: "BLACK, BOLD, ...". All whitespaces are ignored.
type BarChart ¶
type BarChart struct { Block BarColor Attribute TextColor Attribute NumColor Attribute NumFmt func(int) string Data []int DataLabels []string BarWidth int BarGap int CellChar rune // 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.BorderLabel = "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.
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) InnerBounds ¶
InnerBounds returns the internal bounds of the block after aligning and calculating the padding and border, if any.
func (Block) InnerHeight ¶
func (Block) InnerWidth ¶
type Buffer ¶
Buffer is a renderable rectangle cell data container.
func NewFilledBuffer ¶
NewFilledBuffer returns a new Buffer filled with ch, fb and bg.
type Bufferer ¶
type Bufferer interface {
Buffer() Buffer
}
Bufferer should be implemented by all renderable components.
type Cell ¶
Cell is a rune with assigned Fg and Bg
func DTrimTxCls ¶
DTrimTxCls trims the overflowed text cells sequence and append dots at the end.
func TrimTxCells ¶
TrimTxCells trims the overflowed text cells sequence.
type Gauge ¶
type Grid ¶
Grid implements 12 columns system. A simple example:
import ui "github.com/JBToula/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
type GridBufferer ¶
GridBufferer introduces a Bufferer that can be manipulated by Grid.
type LineChart ¶
type LineChart struct { Block Data map[string][]float64 DataLabels []string // if unset, the data indices will be used Mode string // braille | dot DotStyle rune LineColor map[string]Attribute AxesColor Attribute YPadding float64 YFloor float64 YCeil float64 // contains filtered or unexported fields }
LineChart has two modes: braille(default) and dot. A single braille character is a 2x4 grid of dots, so Using braille gives 2x X resolution and 4x Y resolution over dot mode.
lc := termui.NewLineChart() lc.Border.Label = "braille-mode Line Chart" lc.Data["name'] = [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.
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/JBToula/termui", "[1] editbox.go", "[2] interrupt.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.BorderLabel = "List" ls.Height = 7 ls.Width = 25 ls.Y = 0
type MarkdownTxBuilder ¶
type MarkdownTxBuilder struct {
// contains filtered or unexported fields
}
MarkdownTxBuilder implements TextBuilder interface, using markdown syntax.
type OutputMode ¶
type OutputMode int
termbox passthrough
const ( OutputCurrent OutputMode = iota OutputNormal Output256 Output216 OutputGrayscale )
termbox passthrough
type Paragraph ¶
type Paragraph struct { Block Text string TextFgColor Attribute TextBgColor Attribute WrapLength int // words wrap limit. Note it may not work properly with multi-width char }
Paragraph displays a paragraph.
par := termui.NewParagraph("Simple Text") par.Height = 3 par.Width = 17 par.BorderLabel = "Label"
func NewParagraph ¶
NewParagraph returns a new *Paragraph with given text as its content.
type PieChart ¶
type PieChart struct { Block Data []float64 // list of data items Colors []Attribute // colors to by cycled through (see defaultColors) BorderColor Attribute // color of the pie-border Label PieChartLabel // callback function for labels Offset float64 // which angle to start drawing at? (see piechartOffsetUp) }
func NewPieChart ¶
func NewPieChart() *PieChart
NewPieChart Creates a new pie chart with reasonable defaults and no labels
type PieChartLabel ¶
PieChartLabel callback, i is the current data index, v the current value
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.
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 ¶
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 *Sparklines 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 StackedBarChart ¶
type StackedBarChart struct { Block BarColor [NumberofColors]Attribute TextColor Attribute NumColor [NumberofColors]Attribute NumFmt func(int) string Data [NumberofColors][]int DataLabels []string BarWidth int BarGap int ShowScale bool // contains filtered or unexported fields }
This is the implementation 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.NewStackedBarChart() 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.BorderLabel = "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 NewStackedBarChart ¶
func NewStackedBarChart() *StackedBarChart
NewStackedBarChart returns a new *StackedBarChart with current theme.
func (*StackedBarChart) Buffer ¶
func (bc *StackedBarChart) Buffer() Buffer
Buffer implements Bufferer interface.
func (*StackedBarChart) SetMax ¶
func (bc *StackedBarChart) SetMax(max int)
type TabPane ¶
type TabPane struct { Block Tabs []Tab ActiveTabBg Attribute // contains filtered or unexported fields }
func NewTabPane ¶
func NewTabPane() *TabPane
func (*TabPane) SetActiveLeft ¶
func (tp *TabPane) SetActiveLeft()
func (*TabPane) SetActiveRight ¶
func (tp *TabPane) SetActiveRight()
type Table ¶
type Table struct { Block Rows [][]string CellWidth []int FgColor Attribute BgColor Attribute FgColors []Attribute BgColors []Attribute Separator bool TextAlign Align }
Table tracks all the attributes of a Table instance
func (*Table) Analysis ¶
Analysis generates and returns an array of []Cell that represent all columns in the Table
type TextBuilder ¶
TextBuilder is a minimal interface to produce text []Cell using specific syntax (markdown).
func NewMarkdownTxBuilder ¶
func NewMarkdownTxBuilder() TextBuilder
NewMarkdownTxBuilder returns a TextBuilder employing markdown syntax.
type WgtInfo ¶
func NewWgtInfo ¶
type WgtMgr ¶
event mixins
var DefaultWgtMgr WgtMgr