README.md

December 29, 2025 ยท View on GitHub

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

Featuregotuitermui
Renderertcell (Optimized)termbox
Performance (FPS)~3300 (Heavy Load)~1700
Widgets Available27+ (Calendar, Tree, Button, Checkbox...)~12
Layout SystemFlex + Grid + AbsoluteGrid
CustomizationHigh (Rounded Borders, Alignments)Basic
Pixel-PerfectYes (Braille/Block/Space)No
Mouse SupportFull (Wheel/Click/Drag)Click
TrueColorYesNo
SSH / Multi-UserNative (Backend API)No (Global State)
Modern Terminal SupportAll (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/ExampleScreenshotCode
AlignmentView Example Code
ApplicationView Example Code
BackgroundView Example Code
BarchartView Example Code
BordersView Example Code
BlockView Example Code
Block Multi TitleView Example Code
CalendarView Example Code
CanvasView Example Code
Collapsed BordersView Example Code
ColorsView Example Code
DashboardView Example Code
DemoView Example Code
DonutchartView Example Code
EventsView Example Code
FlexView Example Code
FunnelchartView Example Code
GaugeView Example Code
GradientView Example Code
GridView Example Code
HeatmapView Example Code
Hello WorldView Example Code
ImageView Example Code
InputView Example Code
InteractionView Example Code
LinechartView Example Code
LinegaugeView Example Code
ListView Example Code
LogoView Example Code
ModalView Example Code
Modern DemoView Example Code
ParagraphView Example Code
PiechartView Example Code
PlotView Example Code
RadarchartView Example Code
ScrollbarView Example Code
SparklineView Example Code
SpinnerView Example Code
Ssh-DashboardView Example Code
Stacked BarchartView Example Code
StepchartView Example Code
TableView Example Code
TabsView Example Code
TextareaView Example Code
TreeView Example Code
TreemapView 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.