# tview — Rich Interactive Terminal UI Widgets for Go > tview is a Go library for building rich terminal user interfaces with interactive widgets including tables, forms, trees, text views, and modal dialogs. It is built on top of tcell and provides a high-level API for composing complex TUI layouts. ## Install Save in your project root: # tview — Rich Interactive Terminal UI Widgets for Go ## Quick Use ```bash # Add tview to your Go project go get github.com/rivo/tview # Minimal example cat > main.go << 'EOF2' package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() box := tview.NewBox().SetBorder(true).SetTitle("Hello tview") if err := app.SetRoot(box, true).Run(); err != nil { panic(err) } } EOF2 go run main.go ``` ## Introduction tview brings desktop-class UI widgets to the terminal. It provides ready-made components like tables with sortable columns, tree views, form inputs, drop-downs, and flex-based layouts. Built on the tcell terminal library, tview handles cross-platform terminal differences and provides mouse support, colors, and Unicode rendering. ## What tview Does - Provides 15+ ready-made widgets: Table, TreeView, Form, InputField, DropDown, List, Modal, and more - Supports flexible layouts with Flex (horizontal/vertical) and Grid containers - Handles keyboard navigation, mouse clicks, and focus management automatically - Renders with full Unicode support, 256 colors, and true-color terminals - Manages concurrent UI updates safely with `Application.QueueUpdateDraw()` ## Architecture Overview tview is layered on top of tcell, which handles terminal I/O and screen management. Each widget implements the `Primitive` interface (Draw, GetRect, SetRect, InputHandler, Focus). The application runs an event loop that dispatches keyboard and mouse events to the focused widget. Layout containers (Flex, Grid, Pages) compose widgets into complex screen arrangements. Screen updates use double buffering via tcell. ## Self-Hosting & Configuration - Add the dependency: `go get github.com/rivo/tview` - No CGo or system library dependencies; pure Go for easy cross-compilation - Set the terminal's color mode: tview auto-detects but can be overridden via `TERM` variable - Use `Pages` widget for multi-screen navigation (tabs, modals, wizards) - Thread-safe updates via `app.QueueUpdateDraw()` for goroutine-driven data changes ## Key Features - Table widget supports thousands of rows with lazy loading via `SetContent()` callback - TreeView displays hierarchical data with expandable/collapsible nodes - Form widget builds input forms with text fields, checkboxes, drop-downs, and buttons - Built-in text markup for colors and styles: `[red]Warning[white] text` - Mouse support for clicking, scrolling, and selecting across all widgets ## Comparison with Similar Tools - **Bubble Tea** — Bubble Tea uses The Elm Architecture (functional); tview uses an object-oriented widget model - **tcell** — tcell is the low-level terminal library; tview adds high-level widgets on top of it - **termui** — termui focuses on dashboards and charts; tview provides interactive form and table widgets - **gocui** — gocui is simpler with manual widget positioning; tview handles layout automatically - **Textual (Python)** — Textual is Python-based with CSS styling; tview is Go-native with code-driven layout ## FAQ **Q: Can tview handle large datasets in tables?** A: Yes. Use `SetContent()` with a virtual table model that loads rows on demand, supporting millions of rows efficiently. **Q: Does tview support mouse input?** A: Yes. Mouse clicks, scrolling, and selection work in terminals that support mouse events. Enable with `app.EnableMouse(true)`. **Q: How do I update the UI from a goroutine?** A: Use `app.QueueUpdateDraw(func() { /* update widgets */ })` to safely modify widgets from any goroutine. **Q: Can I combine tview with other tcell-based code?** A: Yes. tview exposes the underlying tcell screen, and custom widgets can implement the Primitive interface. ## Sources - https://github.com/rivo/tview - https://pkg.go.dev/github.com/rivo/tview - https://github.com/rivo/tview/wiki --- Source: https://tokrepo.com/en/workflows/asset-a00f6986 Author: AI Open Source