Skip to content

Guide · Open source

How to use tview: build terminal UIs in Go

Updated · written with AI from the project's own documentation and checked against our catalogue data

tview is a Go package that provides ready-made building blocks for terminal programs, including input forms, tables, lists, tree views, text areas and modal windows. It is aimed at Go developers who want interactive screens that run inside a terminal instead of a graphical window. After this guide you will know how to add tview to a Go project and run a minimal program that draws a bordered box in your terminal.

tviewrivo/tview · ★ 14.1k · MIT

Quick start

  1. 1Install Go. tview needs Go installed on your machine. Set up a Go project directory before you add the package.
  2. 2Add the package. Run go get github.com/rivo/tview@master inside your project to add tview as a dependency.
  3. 3Create a main file. Write a Go file with a main function that imports github.com/rivo/tview.
  4. 4Build a widget. Create a widget, such as a box with a border and title, using the tview constructors.
  5. 5Run the application. Pass the widget to tview.NewApplication().SetRoot and call Run to display it in the terminal.
  6. 6Explore the demos. Open the demos subdirectory and the GitHub Wiki to find examples of forms, tables and lists.

Install tview in your Go project

tview is a Go package, so you need Go installed first. To add it to your project, run the command from the project's README inside your Go project directory.

  • Prerequisite: Go
  • The package is pulled in with go get, as shown in the README
go get github.com/rivo/tview@master

Run a Hello World example

The README's basic example creates a box with a border and the title "Hello, world!" and displays it in your terminal. It creates an application, sets the box as its root element and runs it. Save the code as a Go file in your project and run it with go run.

If the application fails to start, the example panics with the returned error, so the error is printed to your terminal.

package main import ( "github.com/rivo/tview" ) func main() { box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } }

Choose the right widget for your screen

tview includes input forms (text input, selections, checkboxes and buttons), navigable multi-colour text views, editable multi-line text areas, table views, tree views, selectable lists, images, grid, flexbox and page layouts, modal message windows and an application wrapper. Pick the widget that matches what the user needs to do on that screen, then combine widgets with layouts to build the full interface.

  • Forms for entering data and choosing options
  • Tables and lists for browsing and selecting records
  • Tree views for hierarchical data such as directories
  • Text areas for editing multi-line text
  • Modal windows for short messages and confirmations
  • Grid, flexbox and page layouts to arrange several widgets

Customise and extend components

According to the README, the components come with many customisation options and can be extended to fit your needs. Changes are made through the widget objects in Go code. The README points to the GitHub Wiki for more examples with screenshots, and to the demos subdirectory of the repository for runnable examples.

  • Read the GitHub Wiki for examples with screenshots
  • Run the programs in the demos subdirectory
  • Compile and run demos/presentation for a presentation about the package

Look at real projects built with tview

The README lists many projects that use tview, including K9s (a Kubernetes CLI), a Docker TUI client and a Redis browser. Reading the source of a project that fits your use case is a practical way to see how the widgets are wired together.

What people use it for

  • A Go command-line tool with a menu or form for entering settings
  • A terminal dashboard that shows data in tables and lists
  • A file browser that displays folders in a tree view
  • A terminal client for a service, such as a Docker or Redis browser, as seen in the projects list

Frequently asked questions

Is tview free to use?

tview is released under the MIT licence, as stated in the project information. You can read the licence file in the repository to confirm the terms for your own use.

What do I need to install tview?

You need Go installed. The package is added to a project with go get github.com/rivo/tview@master, as shown in the README.

Is tview a finished app I can download?

No. tview is a library for developers. You need to write a Go program that uses it to get an interactive screen.

Can I use tview with languages other than Go?

No. The package is written for the Go language, so it is only useful in Go projects.

Can tview build a graphical desktop or web interface?

No. tview is for interfaces that run inside a terminal. For graphical or web interfaces you would need a different tool.

How does tview compare with bubbletea, tcell, termui and gocui?

The project information lists bubbletea, tcell, termui and gocui as comparable projects. tview focuses on prebuilt widgets such as forms, tables, lists and tree views, so compare the widgets you need in each library before choosing.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

tview suits Go developers who want prebuilt terminal widgets such as forms, tables, lists and tree views instead of drawing everything by hand. It is not suitable if you want a finished application to run, if you do not use Go, or if you need a graphical or web interface.

Install options & downloads