Documentation
¶
Overview ¶
Package gotui 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 ResolveBorderRune(existing, newRune rune) rune
- 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 ( BorderTop = 1 // 0001 BorderRight = 2 // 0010 BorderBottom = 4 // 0100 BorderLeft = 8 // 1000 )
Border Connections Bitmask
const ( DOT = '•' ELLIPSES = '…' UP_ARROW = '▲' DOWN_ARROW = '▼' COLLAPSED = '+' EXPANDED = '−' )
const ( TOP_LEFT = '┌' TOP_RIGHT = '┐' BOTTOM_LEFT = '└' BOTTOM_RIGHT = '┘' ROUNDED_TOP_LEFT = '╭' ROUNDED_TOP_RIGHT = '╮' ROUNDED_BOTTOM_LEFT = '╰' ROUNDED_BOTTOM_RIGHT = '╯' VERTICAL_LINE = '│' HORIZONTAL_LINE = '─' VERTICAL_LEFT = '┤' VERTICAL_RIGHT = '├' HORIZONTAL_UP = '┴' HORIZONTAL_DOWN = '┬' QUOTA_LEFT = '«' QUOTA_RIGHT = '»' VERTICAL_DASH = '┊' HORIZONTAL_DASH = '┈' )
const (
// Add CROSS if missing from symbols
CROSS = '┼'
)
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 Screen tcell.Screen
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, "grey": ColorGrey, "darkgrey": ColorDarkGrey, "lightgrey": ColorLightGrey, "silver": ColorSilver, "orange": ColorOrange, "purple": ColorPurple, "pink": ColorPink, "coral": ColorCoral, "crimson": ColorCrimson, "gold": ColorGold, "teal": ColorTeal, "turquoise": ColorTurquoise, "indigo": ColorIndigo, "violet": ColorViolet, "olive": ColorOlive, "navy": ColorNavy, "aliceblue": ColorAliceBlue, "beige": ColorBeige, "brown": ColorBrown, "darkblue": ColorDarkBlue, "darkcyan": ColorDarkCyan, "darkgreen": ColorDarkGreen, "darkred": ColorDarkRed, "hotpink": ColorHotPink, "lightblue": ColorLightBlue, "lightgreen": ColorLightGreen, "lime": ColorLime, "maroon": ColorMaroon, "mintcream": ColorMintCream, "mistyrose": ColorMistyRose, "orchid": ColorOrchid, "plum": ColorPlum, "salmon": ColorSalmon, "seagreen": ColorSeaGreen, "skyblue": ColorSkyBlue, "slateblue": ColorSlateBlue, "tan": ColorTan, "tomato": ColorTomato, "wheat": ColorWheat, }
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 tcell 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 tcell, converts them, then sends them to each of its channels.
func ResolveBorderRune ¶
ResolveBorderRune merges an existing rune with a new one.
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
BorderCollapse bool
BorderRounded bool
PaddingLeft, PaddingRight, PaddingTop, PaddingBottom int
image.Rectangle
Inner image.Rectangle
Title string
TitleLeft string
TitleRight string
TitleStyle Style
TitleAlignment Alignment
TitleBottom string
TitleBottomLeft string
TitleBottomRight string
TitleBottomStyle Style
TitleBottomAlignment Alignment
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 ¶
Color is an integer from -1 to 255 -1 = ColorClear 0-255 = Xterm colors
const ( // Standard Colors ColorBlack Color = tcell.ColorBlack ColorRed Color = tcell.ColorRed ColorGreen Color = tcell.ColorGreen ColorYellow Color = tcell.ColorYellow ColorBlue Color = tcell.ColorBlue ColorMagenta Color = tcell.ColorDarkMagenta // Termui legacy mapping ColorCyan Color = tcell.ColorLightCyan // Termui legacy mapping ColorWhite Color = tcell.ColorWhite // Extended Colors (Common) ColorGrey Color = tcell.ColorGrey ColorDarkGrey Color = tcell.ColorDarkGrey ColorLightGrey Color = tcell.ColorLightGrey ColorSilver Color = tcell.ColorSilver ColorOrange Color = tcell.ColorOrange ColorPurple Color = tcell.ColorPurple ColorPink Color = tcell.ColorPink ColorCoral Color = tcell.ColorCoral ColorCrimson Color = tcell.ColorCrimson ColorGold Color = tcell.ColorGold ColorTeal Color = tcell.ColorTeal ColorTurquoise Color = tcell.ColorTurquoise ColorIndigo Color = tcell.ColorIndigo ColorViolet Color = tcell.ColorViolet ColorOlive Color = tcell.ColorOlive ColorAliceBlue Color = tcell.ColorAliceBlue ColorBeige Color = tcell.ColorBeige ColorBrown Color = tcell.ColorBrown ColorDarkBlue Color = tcell.ColorDarkBlue ColorDarkCyan Color = tcell.ColorDarkCyan ColorDarkGreen Color = tcell.ColorDarkGreen ColorDarkRed Color = tcell.ColorDarkRed ColorHotPink Color = tcell.ColorHotPink ColorLightBlue Color = tcell.ColorLightBlue ColorLightGreen Color = tcell.ColorLightGreen ColorLime Color = tcell.ColorLime ColorMaroon Color = tcell.ColorMaroon ColorMintCream Color = tcell.ColorMintCream ColorMistyRose Color = tcell.ColorMistyRose ColorOrchid Color = tcell.ColorOrchid ColorPlum Color = tcell.ColorPlum ColorSalmon Color = tcell.ColorSalmon ColorSeaGreen Color = tcell.ColorSeaGreen ColorSkyBlue Color = tcell.ColorSkyblue ColorSlateBlue Color = tcell.ColorSlateBlue ColorTan Color = tcell.ColorTan ColorTomato Color = tcell.ColorTomato ColorWheat Color = tcell.ColorWheat )
Basic terminal colors
const ColorClear Color = tcell.ColorDefault
ColorClear clears the Fg or Bg color of a Style
func NewColorRGB ¶
NewColorRGB returns a new Color with the given RGB values
func NewRGBColor ¶
NewRGBColor is a convenience alias for NewColorRGB
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 Modifier ¶
const ( // ModifierClear clears any modifiers ModifierClear Modifier = 0 ModifierBold Modifier = tcell.AttrBold ModifierUnderline Modifier = tcell.AttrUnderline ModifierReverse Modifier = tcell.AttrReverse )
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
}
