Configs2026年7月12日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
tview Overview
直接安装命令
npx -y tokrepo@latest install a00f6986-7e30-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产