Documentation ¶
Overview ¶
Package termui is a library for creating terminal user interfaces (TUIs) using widgets.
Index ¶
- Constants
- Variables
- func AbsInt(x int) int
- func CellsToString(cells []Cell) string
- func Clear()
- func Close()
- func FloorFloat64(x float64) float64
- func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error)
- func GetMaxFloat64FromSlice(slice []float64) (float64, error)
- func GetMaxIntFromSlice(slice []int) (int, error)
- func Init() error
- func InterfaceSlice(slice interface{}) []interface{}
- func MaxFloat64(x, y float64) float64
- func MaxInt(x, y int) int
- func MinFloat64(x, y float64) float64
- func MinInt(x, y int) int
- func PollEvents() <-chan Event
- func Render(items ...Drawable)
- func RoundFloat64(x float64) float64
- func SplitCells(cells []Cell, r rune) [][]Cell
- func SumFloat64Slice(data []float64) float64
- func SumIntSlice(slice []int) int
- func TerminalDimensions() (int, int)
- func TrimString(s string, w int) string
- type Alignment
- type BarChartTheme
- type Block
- type BlockTheme
- type Buffer
- type Canvas
- type Cell
- type CellWithX
- type Color
- type Drawable
- type Event
- type EventType
- type GaugeTheme
- type Grid
- type GridItem
- type ListTheme
- type Modifier
- type Mouse
- type ParagraphTheme
- type PieChartTheme
- type PlotTheme
- type Resize
- type RootTheme
- type SparklineTheme
- type StackedBarChartTheme
- type Style
- type TabTheme
- type TableTheme
- type TreeTheme
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.
Functions ¶
func CellsToString ¶
func FloorFloat64 ¶
func GetMaxFloat64FromSlice ¶
func GetMaxIntFromSlice ¶
func Init ¶
func Init() error
Init initializes termbox-go and is required to render anything. After initialization, the library must be finalized with `Close`.
func InterfaceSlice ¶
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 ¶
func MinFloat64 ¶
func PollEvents ¶
func PollEvents() <-chan Event
PollEvents gets events from termbox, converts them, then sends them to each of its channels.
func RoundFloat64 ¶
func SplitCells ¶
func SumFloat64Slice ¶
func SumIntSlice ¶
func TerminalDimensions ¶
func TrimString ¶
TrimString trims a string to a max length and adds '…' to the end if it was trimmed.
Types ¶
type BarChartTheme ¶
type Block ¶
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.
type BlockTheme ¶
type Cell ¶
Cell represents a viewable terminal cell
func ParseStyles ¶
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 ¶
type CellWithX ¶
func BuildCellWithXArray ¶
type Color ¶
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 ¶
type GaugeTheme ¶
type GridItem ¶
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.
type ParagraphTheme ¶
type ParagraphTheme struct {
Text Style
}
type PieChartTheme ¶
type PieChartTheme struct {
Slices []Color
}
type RootTheme ¶
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 ¶
type StackedBarChartTheme ¶
type Style ¶
Style represents the style of one terminal cell
func NewStyle ¶
NewStyle takes 1 to 3 arguments 1st argument = Fg 2nd argument = optional Bg 3rd argument = optional Modifier
func SelectStyle ¶
type TableTheme ¶
type TableTheme struct {
Text Style
}