gotui

package module
v5.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 20 Imported by: 0

README

gotui Logo

gotui

A modern, high-performance Terminal User Interface (TUI) library for Go.

Go Report Card GoDoc License

gotui by Carsen Klock is a fully-customizable dashboard and widget Go library built on top of tcell. It is a modernized enhanced fork of termui, engineered for valid TrueColor support, high-performance rendering, flex layouts, rounded borders, input, and for feature parity with robust libraries like ratatui.


gotui

⚡ Features

  • 🚀 High Performance: optimized rendering engine capable of ~3000 FPS frame operations with zero-allocation drawing loops. (termui is ~1700 FPS)
  • 🎨 TrueColor Support: Full 24-bit RGB color support for modern terminals (Ghostty, Alacritty, Kitty, iTerm2).
  • 📐 Flexible Layouts:
    • Flex: Mixed fixed/proportional layouts.
    • Grid: 12-column dynamic grid system.
    • Absolutes: Exact coordinates when needed.
  • 🌐 SSH / Remote Apps: Turn any TUI into a zero-install SSH accessible application (multi-tenant support).
  • 🎨 Gradient Support: Gradient support for widgets.
  • 📊 Rich Widgets:
    • Charts: BarChart, StackedBarChart, PieChart, DonutChart, RadarChart (Spider), FunnelChart, TreeMap, Sparkline, Plot (Scatter/Line).
    • Gauges: Gauge, LineGauge (with pixel-perfect Braille/Block styles).
    • Interaction: Input, TextArea, List, Table, Scrollbar, Button, Checkbox.
    • Misc: TabPane, Image (block-based), Canvas (Braille), Heatmap, Logo, Spinner, Modal.
  • 📱 Application API: Structured app framework with focus management, event dispatch, and auto-resize.
  • 🖱️ Mouse Support: Full mouse event support (Click, Scroll Wheel, Drag).
  • 🔧 Customizable: Themes, rounded borders, border titles (alignment).

🆚 Comparison

Feature gotui termui
Renderer tcell (Optimized) termbox
Performance (FPS) ~3300 (Heavy Load) ~1700
Widgets Available 27+ (Calendar, Tree, Button, Checkbox...) ~12
Layout System Flex + Grid + Absolute Grid
Customization High (Rounded Borders, Alignments) Basic
Pixel-Perfect Yes (Braille/Block/Space) No
Mouse Support Full (Wheel/Click/Drag) Click
TrueColor Yes No
SSH / Multi-User Native (Backend API) No (Global State)
Modern Terminal Support All (iterm, ghostty, etc.) No

gotui is backward compatible with termui and can mostly be used as a drop-in replacement.

📦 Installation

gotui uses Go modules.

go get github.com/metaspartan/gotui/v5

Requires Go Lang 1.24 or higher.

🚀 Quick Start

Create a main.go:

package main

import (
	"log"

	ui "github.com/metaspartan/gotui/v5"
	"github.com/metaspartan/gotui/v5/widgets"
)

func main() {
	if err := ui.Init(); err != nil {
		log.Fatalf("failed to initialize gotui: %v", err)
	}
	defer ui.Close()

	p := widgets.NewParagraph()
	p.Title = "Hello World"
	p.Text = "PRESS q TO QUIT.\n\nCombined with modern widgets, gotui aims to provide the best TUI experience in Go."
	p.SetRect(0, 0, 50, 5)
	p.TitleStyle.Fg = ui.ColorYellow
	p.BorderStyle.Fg = ui.ColorSkyBlue

	ui.Render(p)

	uiEvents := ui.PollEvents()
	for {
		e := <-uiEvents
		switch e.ID {
		case "q", "<C-c>":
			return
		}
	}
}

Run the main dashboard demo: go run _examples/dashboard/main.go

Run individual examples: go run _examples/<name>/main.go

*Widget Screenshots are auto generated.

Widget/Example Screenshot Code
Alignment View Example Code
Application View Example Code
Background View Example Code
Barchart View Example Code
Borders View Example Code
Block View Example Code
Block Multi Title View Example Code
Calendar View Example Code
Canvas View Example Code
Collapsed Borders View Example Code
Colors View Example Code
Dashboard View Example Code
Demo View Example Code
Donutchart View Example Code
Events View Example Code
Flex View Example Code
Funnelchart View Example Code
Gauge View Example Code
Gradient View Example Code
Grid View Example Code
Heatmap View Example Code
Hello World View Example Code
Image View Example Code
Input View Example Code
Interaction View Example Code
Linechart View Example Code
Linegauge View Example Code
List View Example Code
Logo View Example Code
Modal View Example Code
Modern Demo View Example Code
Paragraph View Example Code
Piechart View Example Code
Plot View Example Code
Radarchart View Example Code
Scrollbar View Example Code
Sparkline View Example Code
Spinner View Example Code
Ssh-Dashboard View Example Code
Stacked Barchart View Example Code
Stepchart View Example Code
Table View Example Code
Tabs View Example Code
Textarea View Example Code
Tree View Example Code
Treemap View Example Code

🛠️ Advanced Usage

Application API

For structured applications with focus management and automatic event dispatch:

package main

import (
	"log"
	"github.com/metaspartan/gotui/v5"
	"github.com/metaspartan/gotui/v5/widgets"
)

func main() {
	app := gotui.NewApp()

	p := widgets.NewParagraph()
	p.Title = "My App"
	p.Text = "Press q or Ctrl+C to quit."

	app.SetRoot(p, true) // Set root widget with focus

	if err := app.Run(); err != nil {
		log.Fatal(err)
	}
}

The Application handles:

  • Terminal initialization/cleanup
  • Automatic resize handling
  • Event dispatch to focused widgets
  • Default quit handlers (q, Ctrl+C)

Customizing Borders

gotui supports multiple border styles and title alignments.

p.Border = true
p.BorderRounded = true   // ╭───╮ instead of ┌───┐
p.Title = "My Title"
p.TitleAlignment = ui.AlignLeft // or AlignCenter, AlignRight
p.TitleBottom = "Page 1"
p.TitleBottomAlignment = ui.AlignRight

// Or use other border styles:
double := ui.BorderSetDouble()
p.BorderSet = &double  // ╔═══╗

thick := ui.BorderSetThick()
p.BorderSet = &thick   // ┏━━━┓

Handling Mouse Events

Events include MouseLeft, MouseRight, MouseRelease, MouseWheelUp, MouseWheelDown.

uiEvents := ui.PollEvents()
for e := range uiEvents {
    if e.Type == ui.MouseEvent {
        // e.ID is "MouseLeft", "MouseWheelUp", etc.
        // e.Payload.X, e.Payload.Y are coordinates
    }
}

🌐 Serving over SSH

You can easily serve your TUI over SSH (like standard CLI apps) using ui.InitWithConfig and a library like gliderlabs/ssh.

func sshHandler(sess ssh.Session) {
    // 1. Create a custom backend for this session
    app, err := ui.NewBackend(&ui.InitConfig{
        CustomTTY: sess, // ssh.Session implements io.ReadWriter
    })
    if err != nil {
        return // Handle error appropriately
    }
    defer app.Close()

    // 2. Use the app instance instead of global ui.* functions
    p := widgets.NewParagraph()
    p.Text = "Hello SSH User!"
    p.SetRect(0, 0, 20, 5)
    
    app.Render(p) // Renders to the SSH client only!
}

Check _examples/ssh-dashboard for a full multi-user demo.

🤝 Contributing

Contributions are welcome! Please submit a Pull Request.

  1. Fork the repo.
  2. Create your feature branch (git checkout -b feature/my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature/my-new-feature).
  5. Create a new Pull Request.

Projects using gotui

Submit a PR to add yours here!

Author(s)

Carsen Klock (https://x.com/carsenklock)

Zack Guo (https://github.com/gizak)

License

MIT

Acknowledgments

Original termui by Zack Guo.

Inspired by Ratatui.

Documentation

Index

Constants

View Source
const (
	BorderTop    = 1
	BorderRight  = 2
	BorderBottom = 4
	BorderLeft   = 8
)
View Source
const (
	BoxDrawingsLightHorizontal            = '─'
	BoxDrawingsLightVertical              = '│'
	BoxDrawingsLightDownAndRight          = '┌'
	BoxDrawingsLightDownAndLeft           = '┐'
	BoxDrawingsLightUpAndRight            = '└'
	BoxDrawingsLightUpAndLeft             = '┘'
	BoxDrawingsLightDownAndHorizontal     = '┬'
	BoxDrawingsLightUpAndHorizontal       = '┴'
	BoxDrawingsLightVerticalAndRight      = '├'
	BoxDrawingsLightVerticalAndLeft       = '┤'
	BoxDrawingsLightVerticalAndHorizontal = '┼'

	BoxDrawingsLightArcDownAndRight = '╭'
	BoxDrawingsLightArcDownAndLeft  = '╮'
	BoxDrawingsLightArcUpAndRight   = '╰'
	BoxDrawingsLightArcUpAndLeft    = '╯'

	BoxDrawingsHeavyHorizontal        = '━'
	BoxDrawingsHeavyVertical          = '┃'
	BoxDrawingsHeavyDownAndRight      = '┏'
	BoxDrawingsHeavyDownAndLeft       = '┓'
	BoxDrawingsHeavyUpAndRight        = '┗'
	BoxDrawingsHeavyUpAndLeft         = '┛'
	BoxDrawingsHeavyDownAndHorizontal = '┳'
	BoxDrawingsHeavyUpAndHorizontal   = '┻'
	BoxDrawingsHeavyVerticalAndRight  = '┣'
	BoxDrawingsHeavyVerticalAndLeft   = '┫'

	BoxDrawingsDoubleHorizontal        = '═'
	BoxDrawingsDoubleVertical          = '║'
	BoxDrawingsDoubleDownAndRight      = '╔'
	BoxDrawingsDoubleDownAndLeft       = '╗'
	BoxDrawingsDoubleUpAndRight        = '╚'
	BoxDrawingsDoubleUpAndLeft         = '╝'
	BoxDrawingsDoubleDownAndHorizontal = '╦'
	BoxDrawingsDoubleUpAndHorizontal   = '╩'
	BoxDrawingsDoubleVerticalAndRight  = '╠'
	BoxDrawingsDoubleVerticalAndLeft   = '╣'
)
View Source
const (
	GradientHorizontal int = 0
	GradientVertical   int = 1
)
View Source
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      = '┈'
	COLLAPSED            = '+'
	EXPANDED             = '−'
	ELLIPSES             = '…'
	UP_ARROW             = '▲'
	DOWN_ARROW           = '▼'
	DOT                  = '•'
)
View Source
const (
	CROSS = '┼'
)

Variables

View Source
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', '⠠', '⠐', '⠈'}
)
View Source
var CellClear = Cell{
	Rune:  ' ',
	Style: StyleClear,
}
View Source
var DefaultBackend = &Backend{}

DefaultBackend is the default backend.

View Source
var Screen tcell.Screen

Screen is the default screen. Deprecated: Use DefaultBackend.Screen instead.

View Source
var ScreenshotMode bool

ScreenshotMode is the default screenshot mode. Deprecated: Use DefaultBackend.ScreenshotMode instead.

View Source
var StyleClear = Style{
	Fg:       ColorClear,
	Bg:       ColorClear,
	Modifier: ModifierClear,
}
View Source
var StyleParserColorMap = map[string]Color{
	"red":        ColorRed,
	"blue":       ColorBlue,
	"black":      ColorBlack,
	"cyan":       ColorLightCyan,
	"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,
}
View Source
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),
	},
}

Functions

func AbsInt

func AbsInt(x int) int

AbsInt returns the absolute value of an int.

func Capture

func Capture(width, height int, items ...Drawable) *image.RGBA

func CellsToString

func CellsToString(cells []Cell) string

CellsToString converts a slice of cells to a string.

func Clear

func Clear()

func ClearBackground

func ClearBackground(c Color)

func Close

func Close()

func FloorFloat64

func FloorFloat64(x float64) float64

FloorFloat64 floors a float64.

func GetMaxFloat64From2dSlice

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

GetMaxFloat64From2dSlice returns the maximum value from a 2D slice of float64s.

func GetMaxFloat64FromSlice

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

GetMaxFloat64FromSlice returns the maximum value from a slice of float64s.

func GetMaxIntFromSlice

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

GetMaxIntFromSlice returns the maximum value from a slice of ints.

func Init

func Init() error

func InitWithConfig

func InitWithConfig(cfg *InitConfig) error

func InterfaceSlice

func InterfaceSlice(slice any) []any

InterfaceSlice converts a slice of any type to a slice of interface{}.

func MaxFloat64

func MaxFloat64(x, y float64) float64

MaxFloat64 returns the maximum of two float64s.

func MaxInt

func MaxInt(x, y int) int

MaxInt returns the maximum of two ints.

func MinFloat64

func MinFloat64(x, y float64) float64

MinFloat64 returns the minimum of two float64s.

func MinInt

func MinInt(x, y int) int

MinInt returns the minimum of two ints.

func PollEvents

func PollEvents() <-chan Event

PollEvents polls for events.

func PollEventsWithContext

func PollEventsWithContext(ctx context.Context) <-chan Event

PollEventsWithContext polls for events with a context.

func Render

func Render(items ...Drawable)

Render renders the given drawables to the screen.

func RenderBufferToImage

func RenderBufferToImage(buf *Buffer) *image.RGBA

func ResolveBorderRune

func ResolveBorderRune(existing, newRune rune) rune

func RoundFloat64

func RoundFloat64(x float64) float64

RoundFloat64 rounds a float64 to the nearest integer.

func SaveImage

func SaveImage(path string, width, height int, items ...Drawable) error

func SplitCells

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

SplitCells splits a slice of cells by a rune.

func SumFloat64Slice

func SumFloat64Slice(data []float64) float64

SumFloat64Slice sums a slice of float64s.

func SumIntSlice

func SumIntSlice(slice []int) int

SumIntSlice sums a slice of ints.

func TerminalDimensions

func TerminalDimensions() (int, int)

func TrimString

func TrimString(s string, w int) string

TrimString trims a string to a given width.

Types

type Alignment

type Alignment uint

Alignment represents the alignment of text.

const (
	AlignLeft Alignment = iota
	AlignCenter
	AlignRight
)

type Application

type Application struct {
	Backend *Backend
	sync.Mutex
	// contains filtered or unexported fields
}

Application represents the application.

func NewApp

func NewApp() *Application

NewApp returns a new Application.

func (*Application) Run

func (a *Application) Run() error

Run runs the application.

func (*Application) SetFocus

func (a *Application) SetFocus(p Widget)

SetFocus sets the focus to the given widget.

func (*Application) SetRoot

func (a *Application) SetRoot(root Widget, focus bool)

SetRoot sets the root widget of the application. If focus is true, the root widget is also focused.

func (*Application) Stop

func (a *Application) Stop()

Stop stops the application.

type Backend

type Backend struct {
	Screen         tcell.Screen
	ScreenshotMode bool
}

Backend represents the backend.

func NewBackend

func NewBackend(cfg *InitConfig) (*Backend, error)

func (*Backend) Clear

func (b *Backend) Clear()

func (*Backend) ClearBackground

func (b *Backend) ClearBackground(c Color)

func (*Backend) Close

func (b *Backend) Close()

func (*Backend) Init

func (b *Backend) Init() error

func (*Backend) InitWithConfig

func (b *Backend) InitWithConfig(cfg *InitConfig) error

func (*Backend) PollEvents

func (b *Backend) PollEvents() <-chan Event

PollEvents polls for events.

func (*Backend) PollEventsWithContext

func (b *Backend) PollEventsWithContext(ctx context.Context) <-chan Event

PollEventsWithContext polls for events with a context.

func (*Backend) Render

func (b *Backend) Render(items ...Drawable)

func (*Backend) TerminalDimensions

func (b *Backend) TerminalDimensions() (int, int)

type BarChartTheme

type BarChartTheme struct {
	Bars   []Color
	Nums   []Style
	Labels []Style
}

type Block

type Block struct {
	Border                                               bool
	BorderStyle                                          Style
	BackgroundColor                                      Color
	FillBorder                                           bool
	BorderLeft, BorderRight, BorderTop, BorderBottom     bool
	BorderCollapse                                       bool
	BorderRounded                                        bool
	BorderType                                           BorderType
	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
	BorderGradient       Gradient
	BorderSet            *BorderSet
	sync.Mutex
}

Block is the base struct for all widgets.

func NewBlock

func NewBlock() *Block

NewBlock returns a new Block.

func (*Block) Draw

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

Draw draws the block to the buffer.

func (*Block) GetRect

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

GetRect returns the rectangle of the block.

func (*Block) HandleEvent

func (b *Block) HandleEvent(e Event) bool

HandleEvent handles events. This is a default implementation for Block that returns false, meaning the event was not handled. Embedders should override this method to handle specific events.

func (*Block) SetRect

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

SetRect sets the rectangle of the block.

type BlockTheme

type BlockTheme struct {
	Title  Style
	Border Style
}

type BorderSet

type BorderSet struct {
	Top         rune
	Bottom      rune
	Left        rune
	Right       rune
	TopLeft     rune
	TopRight    rune
	BottomLeft  rune
	BottomRight rune
	TopT        rune
	BottomT     rune
	LeftT       rune
	RightT      rune
}

BorderSet defines various borders used when primitives are drawn.

func BorderSetDouble

func BorderSetDouble() BorderSet

func BorderSetHidden

func BorderSetHidden() BorderSet

func BorderSetPlain

func BorderSetPlain() BorderSet

func BorderSetRound

func BorderSetRound() BorderSet

func BorderSetThick

func BorderSetThick() BorderSet

type BorderType

type BorderType int
const (
	BorderLine BorderType = iota
	BorderBlock
	BorderDouble
	BorderThick
)

type Borders

type Borders uint
const (
	BordersTop Borders = 1 << iota
	BordersBottom
	BordersLeft
	BordersRight

	BordersNone Borders = 0
	BordersAll  Borders = BordersTop | BordersBottom | BordersLeft | BordersRight
)

func (Borders) Has

func (b Borders) Has(flag Borders) bool

type Buffer

type Buffer struct {
	image.Rectangle
	Cells []Cell
}

Buffer represents a buffer of cells.

func NewBuffer

func NewBuffer(r image.Rectangle) *Buffer

NewBuffer returns a new Buffer.

func (*Buffer) Fill

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

Fill fills the buffer with the given cell.

func (*Buffer) GetCell

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

GetCell returns the cell at the given point.

func (*Buffer) SetCell

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

SetCell sets the cell at the given point.

func (*Buffer) SetString

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

SetString writes a string to the buffer at the given point.

type Canvas

type Canvas struct {
	Block
	drawille.Canvas
}

Canvas is a widget that allows drawing points and lines using braille characters.

func NewCanvas

func NewCanvas() *Canvas

NewCanvas returns a new Canvas.

func (*Canvas) Draw

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

Draw draws the canvas to the buffer.

func (*Canvas) SetLine

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

SetLine draws a line from p0 to p1 with the given color.

func (*Canvas) SetPoint

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

SetPoint sets the color of the point at the given coordinates.

type Cell

type Cell struct {
	Rune  rune
	Style Style
}

Cell represents a single cell in the terminal.

func ApplyGradientToText

func ApplyGradientToText(text string, start, end Color) []Cell

ApplyGradientToText applies a gradient to a string of text.

func NewCell

func NewCell(rune rune, args ...any) Cell

func ParseStyles

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

func RunesToStyledCells

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

RunesToStyledCells converts a slice of runes to a slice of cells with a given style.

func TrimCells

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

TrimCells trims a slice of cells to a given width.

func WrapCells

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

WrapCells wraps a slice of cells to a given width.

type CellWithX

type CellWithX struct {
	X    int
	Cell Cell
}

func BuildCellWithXArray

func BuildCellWithXArray(cells []Cell) []CellWithX

BuildCellWithXArray builds an array of CellWithX from a slice of Cells.

type Color

type Color = tcell.Color
const (
	ColorBlack      Color = tcell.ColorBlack
	ColorRed        Color = tcell.ColorRed
	ColorGreen      Color = tcell.ColorGreen
	ColorYellow     Color = tcell.ColorYellow
	ColorBlue       Color = tcell.ColorBlue
	ColorMagenta    Color = tcell.ColorDarkMagenta
	ColorLightCyan  Color = tcell.ColorLightCyan
	ColorWhite      Color = tcell.ColorWhite
	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
	ColorNavy       Color = tcell.ColorNavy
	ColorAliceBlue  Color = tcell.ColorAliceBlue
	ColorBeige      Color = tcell.ColorBeige
	ColorBrown      Color = tcell.ColorBrown
	ColorDarkBlue   Color = tcell.ColorDarkBlue
	ColorCyan       Color = tcell.ColorTeal
	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
)
const ColorClear Color = tcell.ColorDefault

func GenerateGradient

func GenerateGradient(start, end Color, length int) []Color

GenerateGradient generates a gradient from start to end color.

func GenerateMultiGradient

func GenerateMultiGradient(length int, colors ...Color) []Color

GenerateMultiGradient generates a gradient that transitions through multiple colors.

func HexToColor

func HexToColor(hex string) (Color, error)

HexToColor converts a hex color string to a Color.

func InterpolateColor

func InterpolateColor(c1, c2 Color, step, steps int) Color

func NewColorRGB

func NewColorRGB(r, g, b int32) Color

func NewRGBColor

func NewRGBColor(r, g, b int32) Color

func SelectColor

func SelectColor(colors []Color, index int) Color

SelectColor selects a color from a slice of colors based on an index.

type Drawable

type Drawable interface {
	GetRect() image.Rectangle
	SetRect(int, int, int, int)
	Draw(*Buffer)
	sync.Locker
}

Drawable represents a widget that can be drawn to the buffer.

type Event

type Event struct {
	Type    EventType
	ID      string
	Payload any
}

Event represents an event that occurred.

type EventHandler

type EventHandler interface {
	HandleEvent(Event) bool
}

EventHandler represents a widget that can handle events.

type EventType

type EventType uint

EventType represents the type of an event.

const (
	KeyboardEvent EventType = iota
	MouseEvent
	ResizeEvent
)

type GaugeTheme

type GaugeTheme struct {
	Bar   Color
	Label Style
}

type Gradient

type Gradient struct {
	Enabled   bool
	Start     Color
	End       Color
	Stops     []Color
	Direction int
}

Gradient represents a color gradient.

type Grid

type Grid struct {
	Block
	Items []*GridItem
}

Grid allows you to lay out widgets in a grid.

func NewGrid

func NewGrid() *Grid

NewGrid returns a new Grid.

func (*Grid) Draw

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

Draw draws the grid to the buffer.

func (*Grid) Set

func (g *Grid) Set(entries ...any)

Set sets the items in the grid.

type GridItem

type GridItem struct {
	Type        gridItemType
	XRatio      float64
	YRatio      float64
	WidthRatio  float64
	HeightRatio float64
	Entry       any
	IsLeaf      bool
	// contains filtered or unexported fields
}

GridItem represents an item in the grid.

func NewCol

func NewCol(ratio float64, i ...any) GridItem

NewCol creates a new column with the given size ratio and items.

func NewRow

func NewRow(ratio float64, i ...any) GridItem

NewRow creates a new row with the given size ratio and items.

type InitConfig

type InitConfig struct {
	CustomTTY      TTYHandle
	Width, Height  int
	SimulationMode bool
	SimulationSize image.Point
}

InitConfig represents the configuration for initializing the library.

type ListTheme

type ListTheme struct {
	Text Style
}

type Modifier

type Modifier = tcell.AttrMask
const (
	ModifierClear   Modifier = 0
	ModifierBold    Modifier = tcell.AttrBold
	ModifierReverse Modifier = tcell.AttrReverse
	ModifierDim     Modifier = tcell.AttrDim
	ModifierBlink   Modifier = tcell.AttrBlink
	ModifierItalic  Modifier = tcell.AttrItalic
	ModifierStrike  Modifier = tcell.AttrStrikeThrough
)

type Mouse

type Mouse struct {
	Drag bool
	X    int
	Y    int
}

type ParagraphTheme

type ParagraphTheme struct {
	Text Style
}

type PieChartTheme

type PieChartTheme struct {
	Slices []Color
}

type PlotTheme

type PlotTheme struct {
	Lines []Color
	Axes  Color
}

type Resize

type Resize struct {
	Width  int
	Height int
}

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 SparklineTheme struct {
	Title Style
	Line  Color
}

type StackedBarChartTheme

type StackedBarChartTheme struct {
	Bars   []Color
	Nums   []Style
	Labels []Style
}

type Style

type Style struct {
	Fg       Color
	Bg       Color
	Modifier Modifier
}

Style represents the style of a cell.

func NewStyle

func NewStyle(fg Color, args ...any) Style

NewStyle returns a new Style.

func SelectStyle

func SelectStyle(styles []Style, index int) Style

SelectStyle selects a style from a slice of styles based on an index.

type TTYHandle

type TTYHandle interface {
	io.ReadWriter
}

TTYHandle represents a handle to a TTY.

type TabTheme

type TabTheme struct {
	Active   Style
	Inactive Style
}

type TableTheme

type TableTheme struct {
	Text Style
}

TableTheme represents the theme for a table.

type TreeTheme

type TreeTheme struct {
	Text      Style
	Collapsed rune
	Expanded  rune
}

type VerticalAlignment

type VerticalAlignment int
const (
	AlignTop VerticalAlignment = iota
	AlignMiddle
	AlignBottom
)

type Widget

type Widget interface {
	Drawable
	EventHandler
}

Widget represents a Drawable that also handles events.

Directories

Path Synopsis
_examples
alignment command
application command
background command
barchart command
block command
borders command
calendar command
canvas command
colors command
dashboard command
demo command
donutchart command
events command
flex command
funnelchart command
gauge command
gradient command
grid command
heatmap command
hello_world command
image command
input command
interaction command
linechart command
linegauge command
list command
logo command
modal command
modern_demo command
modern_table command
paragraph command
piechart command
plot command
radarchart command
scrollbar command
sparkline command
spinner command
ssh-dashboard command
stepchart command
table command
tabs command
textarea command
tree command
treemap command

Jump to

Keyboard shortcuts

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