The Terminal Gets a Web Makeover: Exploring the go-tui Framework
For years, building Terminal User Interfaces (TUIs) in Go has generally meant choosing between two paths: the rigorous, Elm-inspired functional flow of Bubble Tea or the widget-heavy, imperative world of tview.
But a new player has recently emerged that challenges the "terminal-first" mindset by borrowing heavily from the web. go-tui is a declarative TUI framework that feels less like writing low-level terminal logic and more like building a modern web application.
If you’ve ever wished you could use Tailwind-like utility classes and HTML-inspired layouts in your CLI tools, this is the framework you’ve been waiting for.
What makes go-tui different?
Most Go TUI frameworks require you to manually manage state transitions or build complex nested structs. go-tui flips the script by introducing a declarative DSL (Domain Specific Language) and a compiler-driven workflow.
1. The .gsx File Format
Inspired by the popular templ library, go-tui uses a custom file extension: .gsx. Inside these files, you write Go code intermingled with HTML-like tags.
- Type Safety: Before running your app, you run
tui generate. This compiles your.gsxtemplates into standard, type-safe Go code. - Familiarity: If you know JSX or Vue templates, you’ll feel right at home.
2. Tailwind-Style Styling
Forget manual ANSI escape codes or complex Style structs. go-tui implements a subset of Flexbox (powered by a Yoga-inspired engine) and uses utility classes:
<div class="flex-row bg-blue-500 p-1 justify-center">
<text value="Hello World" class="text-white font-bold" />
</div>
3. Reactive State Management
Unlike imperative frameworks where you must tell a widget to "UpdateValue()", go-tui uses reactive state. Using State[T], you simply update a variable, and the framework automatically calculates the "diff" between the current frame and the next, redrawing only what changed.
Key Features at a Glance
| Feature | Description |
|---|---|
| Yoga Flexbox | Handles complex layouts, padding, and alignment effortlessly. |
| Double Buffering | Minimizes terminal "flicker" by only sending changed cells to the screen. |
| Inline Mode | Allows interactive widgets to live inside your shell scrollback rather than taking over the full screen. |
| LSP Support | Comes with dedicated extensions for VS Code and Neovim (via Tree-sitter) for autocomplete in .gsx files. |
Why use it over Bubble Tea or tview?
Choosing a framework depends on your mental model:
- Choose Bubble Tea if you love the "The Elm Architecture" (TEA) and want a functional, highly predictable state loop.
- Choose tview if you need a "batteries-included" library with pre-built, complex widgets like trees and forms.
- Choose `go-tui` if you want to iterate fast using a web-developer's mental model. It is perfect for developers who find the boilerplate of other frameworks over-engineered for simple dashboards or interactive CLI tools.
Getting Started
To try it out, you’ll need to install the generator first:
go install github.com/go-tui/tui/cmd/tui@latest
Create a .gsx file, define your components, and run tui generate. The framework handles the heavy lifting of rendering, event routing, and terminal escape sequences, leaving you to focus on the logic of your app.
The terminal is no longer a "text-only" relic; with frameworks like go-tui, it’s becoming a first-class citizen for high-fidelity, reactive design.
Would you like me to provide a basic code example of a counter app using the .gsx syntax?
