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
TERMvariable - Use
Pageswidget 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.