tooey

package
v0.0.0-...-020cec0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CellClear = Cell{
	Rune:  ' ',
	Style: StyleClear,
}
View Source
var StyleParserColorMap = map[string]tcell.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

Functions

func AbsInt

func AbsInt(x int) int

func CellsToString

func CellsToString(cells []Cell) string

func FloorFloat64

func FloorFloat64(x float64) float64

func GetMaxFloat64From2dSlice

func GetMaxFloat64From2dSlice(slices [][]float64) (float64, error)

func GetMaxFloat64FromSlice

func GetMaxFloat64FromSlice(slice []float64) (float64, error)

func GetMaxIntFromSlice

func GetMaxIntFromSlice(slice []int) (int, error)

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 MaxFloat64(x, y float64) float64

func MaxInt

func MaxInt(x, y int) int

func MinFloat64

func MinFloat64(x, y float64) float64

func MinInt

func MinInt(x, y int) int

func PollEvents

func PollEvents() <-chan Event

PollEvents gets events from termbox, converts them, then sends them to each of its channels.

func RoundFloat64

func RoundFloat64(x float64) float64

func SplitCells

func SplitCells(cells []Cell, r rune) [][]Cell

func SumFloat64Slice

func SumFloat64Slice(data []float64) float64

func SumIntSlice

func SumIntSlice(slice []int) int

func TrimString

func TrimString(s string, w int) string

TrimString trims a string to a max length and adds '…' to the end if it was trimmed.

Types

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.

func NewBlock

func NewBlock() *Block

func (*Block) Draw

func (b *Block) Draw(buf *Buffer)

Draw implements the Drawable interface.

func (*Block) GetRect

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

GetRect implements the Drawable interface.

func (*Block) SetRect

func (b *Block) SetRect(x1, y1, x2, y2 int)

SetRect implements the Drawable interface.

type Buffer

type Buffer struct {
	image.Rectangle
	CellMap map[image.Point]Cell
}

Buffer represents a section of a terminal and is a renderable rectangle of cells.

func NewBuffer

func NewBuffer(r image.Rectangle) *Buffer

func (*Buffer) Fill

func (b *Buffer) Fill(c Cell, rect image.Rectangle)

func (*Buffer) GetCell

func (b *Buffer) GetCell(p image.Point) Cell

func (*Buffer) SetCell

func (b *Buffer) SetCell(c Cell, p image.Point)

func (*Buffer) SetString

func (b *Buffer) SetString(s string, style Style, p image.Point)

type Canvas

type Canvas struct {
	Block
	drawille.Canvas
}

func NewCanvas

func NewCanvas() *Canvas

func (*Canvas) Draw

func (c *Canvas) Draw(buf *Buffer)

func (*Canvas) SetLine

func (c *Canvas) SetLine(p0, p1 image.Point, color Color)

func (*Canvas) SetPoint

func (c *Canvas) SetPoint(p image.Point, color Color)

type Cell

type Cell struct {
	Rune  rune
	Style Style
}

Cell represents a viewable terminal cell

func NewCell

func NewCell(rune rune, args ...interface{}) Cell

NewCell takes 1 to 2 arguments 1st argument = rune 2nd argument = optional style

func ParseStyles

func ParseStyles(s string, defaultStyle Style) []Cell

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

func RunesToStyledCells(runes []rune, style Style) []Cell

func TrimCells

func TrimCells(cells []Cell, w int) []Cell

func WrapCells

func WrapCells(cells []Cell, width uint) []Cell

WrapCells takes []Cell and inserts Cells containing '\n' wherever a linebreak should go.

func (*Cell) IsZeroWidth

func (c *Cell) IsZeroWidth() bool

IsZeroWidth returns true if the rune is a zwc

func (*Cell) Width

func (c *Cell) Width() int

Width returns the width of the cell's rune

type CellWithX

type CellWithX struct {
	X    int
	Cell Cell
}

func BuildCellWithXArray

func BuildCellWithXArray(cells []Cell) []CellWithX

type Event

type Event struct {
	Type    EventType
	ID      string
	Payload interface{}
}

type EventType

type EventType uint
const (
	KeyboardEvent EventType = iota
	MouseEvent
	ResizeEvent
)

type Grid

type Grid struct {
	Block
	Items []*GridItem
}

func NewGrid

func NewGrid() *Grid

func (*Grid) Draw

func (g *Grid) Draw(buf *Buffer)

func (*Grid) Set

func (g *Grid) Set(entries ...interface{})

Set is used to add Columns and Rows to the grid. It recursively searches the GridItems, adding leaves to the grid and calculating the dimensions of the leaves.

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.

func NewCol

func NewCol(ratio float64, i ...interface{}) GridItem

NewCol takes a height percentage and either a widget or a Row or Column

func NewRow

func NewRow(ratio float64, i ...interface{}) GridItem

NewRow takes a width percentage and either a widget or a Row or Column

type Mouse

type Mouse struct {
	Drag bool
	X    int
	Y    int
}

Mouse payload.

type Resize

type Resize struct {
	Width  int
	Height int
}

Resize payload.

Jump to

Keyboard shortcuts

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