Documentation
¶
Overview ¶
package tooey is a library for creating terminal user interfaces (TUIs) using widgets.
Index ¶
- Constants
- Variables
- func AbsInt(x int) int
- func CheckWhichPositionHasFewest(positions []int) int
- func Clear()
- func Close()
- func ContainsNonWhitespace(slice []rune) bool
- func CountWhiteSpace(slice []rune) int
- func CountWordsInRuneSlice(slice []rune) int
- func DrawableDimensions() (int, int)
- func FloorFloat64(x float64) float64
- func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error)
- func GetMaxFloat64FromSlice(slice []float64) (float64, error)
- func GetMaxIntFromSlice(slice []int) (int, error)
- func GetRootScreen() tcell.Screen
- func Init() error
- func InitSim() 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 NormalizeLeftWhitespace(slice []rune) []rune
- func PollEvents() tcell.Event
- func Render(items ...Drawable)
- func RoundFloat64(x float64) float64
- func ShiftRuneSliceLeft(slice []rune) []rune
- func ShiftRuneSliceRight(slice []rune) []rune
- func ShiftRuneWhitespaceToLeft(slice []rune) []rune
- func ShiftRuneWhitespaceToRight(slice []rune) []rune
- func SpreadWhitespaceAcrossSliceInterior(slice []rune) []rune
- func SumFloat64Slice(data []float64) float64
- func SumIntSlice(slice []int) int
- func Sync()
- func TerminalDimensions() (int, int)
- func TrimString(s string, w int) string
- type Alignment
- type Border
- type Chars
- type Color
- type Container
- type ContainerChild
- type Drawable
- type Element
- type FlexDirection
- type Padding
- type Rectangle
- func (r *Rectangle) DrawableHeight() int
- func (r *Rectangle) DrawableWidth() int
- func (r *Rectangle) GetInnerRect() image.Rectangle
- func (r *Rectangle) GetRect() image.Rectangle
- func (r *Rectangle) InnerX1() int
- func (r *Rectangle) InnerX2() int
- func (r *Rectangle) InnerY1() int
- func (r *Rectangle) InnerY2() int
- func (r *Rectangle) SetRect(x1 int, y1 int, x2 int, y2 int)
- func (r *Rectangle) X1() int
- func (r *Rectangle) X2() int
- func (r *Rectangle) Y1() int
- func (r *Rectangle) Y2() int
- func (r *Rectangle) ZeroSize() bool
- type Style
- type Theme
- type Title
Constants ¶
const ( ColorClear tcell.Color = tcell.ColorDefault ColorBlack tcell.Color = tcell.ColorBlack ColorRed tcell.Color = tcell.ColorRed ColorGreen tcell.Color = tcell.ColorGreen ColorYellow tcell.Color = tcell.ColorYellow ColorBlue tcell.Color = tcell.ColorBlue ColorMagenta tcell.Color = tcell.ColorDarkMagenta ColorCyan tcell.Color = tcell.ColorLightCyan ColorWhite tcell.Color = tcell.ColorWhite )
Basic terminal colors
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 = '┈' )
const ( DefaultULCorner = tcell.RuneULCorner DefaultURCorner = tcell.RuneURCorner DefaultLLCorner = tcell.RuneLLCorner DefaultLRCorner = tcell.RuneLRCorner DefaultHLine = tcell.RuneHLine DefaultVLine = tcell.RuneVLine )
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{ {0, 0}: '⣀', {0, 1}: '⡠', {0, 2}: '⡐', {0, 3}: '⡈', {1, 0}: '⢄', {1, 1}: '⠤', {1, 2}: '⠔', {1, 3}: '⠌', {2, 0}: '⢂', {2, 1}: '⠢', {2, 2}: '⠒', {2, 3}: '⠊', {3, 0}: '⢁', {3, 1}: '⠡', {3, 2}: '⠑', {3, 3}: '⠉', } SINGLE_BRAILLE_LEFT = [4]rune{'\u2840', '⠄', '⠂', '⠁'} SINGLE_BRAILLE_RIGHT = [4]rune{'\u2880', '⠠', '⠐', '⠈'} )
var CornersOnlyBorderChars = &Chars{
HLine: ' ',
VLine: ' ',
ULCorner: '◤',
URCorner: '◥',
LLCorner: '◣',
LRCorner: '◢',
}
CornersOnlyBorderChars will only render corners with triangle ascii
var DefaultStylized = &Chars{ HLine: DefaultHLine, VLine: DefaultVLine, ULCorner: '╒', URCorner: DefaultURCorner, LLCorner: DefaultLLCorner, LRCorner: DefaultLRCorner, }
var DefaultTheme = &Theme{ Default: StyleDefault, Element: StyleClear, Border: StyleDefault, Title: StyleDefault, Text: StyleDefault, Chars: NewDefaultChars(), }
DefaultTheme is a basic white foreground and black background for all elements
var DoubleBarBorderChars = &Chars{
HLine: '═',
VLine: '║',
ULCorner: '╔',
URCorner: '╗',
LLCorner: '╚',
LRCorner: '╝',
}
DoubleBarBorder is like the Default border but with double bars for more dramatic effect // rune(2550)
var RoundedBarBorderChars = &Chars{ HLine: DefaultHLine, VLine: DefaultVLine, ULCorner: '╭', URCorner: '╮', LLCorner: '╰', LRCorner: '╯', }
RoundedBarBorderChars is like the Default border but the corners are rounded
var StyleClassicTerminal = Style{ Style: tcell.StyleDefault.Foreground(tcell.ColorLightGreen).Background(tcell.ColorBlack), Align: AlignFull, }
StyleClassicTerminal is a classic green-on-black terminal styling
var StyleClear = Style{ Style: tcell.StyleDefault, }
StyleClear represents an empty Style, with no colors or modifiers
var StyleDefault = Style{ Style: tcell.StyleDefault.Foreground(ColorWhite).Background(ColorBlack), Align: AlignFull, }
StyleDefault represents a simple white on black default
Functions ¶
func CheckWhichPositionHasFewest ¶
CheckWhichPositionHasFewest returns index of the position with the lowest count
func ContainsNonWhitespace ¶
ContainsNonWhitespace returns true if a given rune slice has any non-whitespace runes
func CountWhiteSpace ¶
CountWhiteSpace returns a count of the number of space characters in a []rune
func CountWordsInRuneSlice ¶
CountWordsInRuneSlice counts how many blocks of non-whitespace characters are inside the rune
This can be used to traverse whitespace between the left and right boundaries use count-1 for right bound to prevent traversing outside of the word bounds
func DrawableDimensions ¶
DrawableDimensions is the same as TerminalDimensions -1 to represent visibly drawable space in most terminals
func FloorFloat64 ¶
func GetMaxFloat64FromSlice ¶
func GetMaxIntFromSlice ¶
func GetRootScreen ¶
func GetRootScreen() tcell.Screen
GetRootScreen returns the root screen tooey writes to
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 NormalizeLeftWhitespace ¶
func PollEvents ¶
func PollEvents() tcell.Event
PollEvents returns a poll of events for the root screen
func RoundFloat64 ¶
func ShiftRuneSliceLeft ¶
ShiftRuneSliceLeft takes a []rune and shifts everything left, wrapping the right most character back to the right most position
func ShiftRuneSliceRight ¶
ShiftRuneSliceRight takes a []rune and shifts everything right, wrapping the right most character back to the left most position
func ShiftRuneWhitespaceToLeft ¶
ShiftRuneWhitespaceToLeft takes a []rune and moves all whitespace to the left
func ShiftRuneWhitespaceToRight ¶
ShiftRuneWhitespaceToRight takes a []rune and moves all whitespace to the right
func SpreadWhitespaceAcrossSliceInterior ¶
SpreadWhitespaceAcrossSliceInterior takes a []rune
and attempts to distribute it's whitespace across the width of the slice interior but not at the outside edges
Take the string "abc def gh ij "
"abc_def___gh_ij___" would try to make "abc___def__gh___ij" "__abc_def___gh_ij" would try to make "abc__def__gh___ij"
func SumFloat64Slice ¶
func SumIntSlice ¶
func TerminalDimensions ¶
Terminal dimensions returns an aggregate dimension for the terminal but it often is clipped on the right and buttom Use DrawableDimensions to get visible terminal dimensions
func TrimString ¶
TrimString trims a string to a max length and adds '…' to the end if it was trimmed.
Types ¶
type Alignment ¶
type Alignment uint
Alignment provides a mechanism for Styles to control alignment of certain elements Not widely employed but can be at the widget level
type Border ¶
type Border struct { Enabled bool Theme *Theme Chars *Chars Left bool Top bool Right bool Bottom bool }
Border contains the definition and drawing logic of an element border
func NewDefaultBorder ¶
NewDefaultBorder returns a border with the default character set
type Chars ¶
Chars is to enable theming border characters
func NewDefaultChars ¶
func NewDefaultChars() *Chars
NewDefaultChars returns the default character set for borders
type Color ¶
type Color tcell.Color
Color is an integer from -1 to 255 -1 = ColorClear 0-255 = Xterm colors
func SelectColor ¶
type Container ¶
type Container struct { Element Direction FlexDirection Children []ContainerChild Theme *Theme }
Container is an element that holds other elements within
func NewContainer ¶
NewContainer returns a new default configuration Container
A theme can be passed at this time or nil for defaults or to configure later
func (*Container) Draw ¶
func (c *Container) Draw(s tcell.Screen)
Draw draws the row or col flex and their children
func (*Container) DrawFlexColumn ¶
func (c *Container) DrawFlexColumn(s tcell.Screen)
DrawFlexColumn will draw the contents as a flexible column
func (*Container) DrawFlexRow ¶
func (c *Container) DrawFlexRow(s tcell.Screen)
DrawFlexRow will draw the contents as a flexible row
func (*Container) RecursiveWrap ¶
func (c *Container) RecursiveWrap(child ContainerChild)
RecursiveWrap wraps a tree of children
type ContainerChild ¶
ContainerChild which represents a member of the flex Grow is added up then divided by the total grow to find the ratio of space each child will consume
func NewFlexChild ¶
func NewFlexChild(grow float64, i ...interface{}) ContainerChild
NewFlexChild produces a ContainerChild which can be Wrapped
type Drawable ¶
type Drawable interface { GetRect() image.Rectangle GetInnerRect() image.Rectangle // SetRect x1, y1, x2, y2 SetRect(int, int, int, int) Draw(tcell.Screen) SetTheme(*Theme) sync.Locker }
Drawable represents a renderable item
type Element ¶
Element is the base drawable struct inherited by most widgets Element manages size, positin, inner drawable space All other ui elements will inherit
func NewElement ¶
NewElement returns a stable empty Element ready to be modified
func (*Element) Draw ¶
func (e *Element) Draw(s tcell.Screen)
Draw call on the element to write to the tcell.Screen
func (*Element) SetBorderCharacters ¶
SetBorderCharacters allows you to set the border characters for an element without touching the theme
type FlexDirection ¶
type FlexDirection uint
const ( FlexColumn FlexDirection = iota FlexColumnReverse // NOT IMPLEMENTED FlexRow FlexRowReverse // NOT IMPLEMENTED )
type Padding ¶
Padding provides an inset from an outer edge
func NewDefaultPadding ¶
func NewDefaultPadding() *Padding
NewDefaultPadding returns a global padding of 1 all around which can account for a basic border
func NewTitlePadding ¶
func NewTitlePadding() *Padding
NewTitlePadding returns a left & right padding of 2 to give the title more room to breathe
type Rectangle ¶
type Rectangle struct { image.Rectangle // Padding should only affect objects within a rectangle // not the outer bounds of the rectangle Padding *Padding sync.Mutex }
Rectangle is a convenience extension of the stdlib image.Rectangle
func NewRectangle ¶
func (*Rectangle) DrawableHeight ¶
DrawableHeight returns the max height of the rectangle minux padding
func (*Rectangle) DrawableWidth ¶
DrawableWidth returns the max width of the rectangle minus padding
func (*Rectangle) GetInnerRect ¶
GetInnerRect returns the bounds of the inner padded rectangle
type Style ¶
type Style struct { tcell.Style Align Alignment }
Style represents the style of one terminal cell
func SelectStyle ¶
type Theme ¶
Theme is a bundle of Styles for different elements, subelements, and widgets If Inherit is true in the theme, then when a theme is set it will propagate the Default down to the others