Convert Figma logo to code with AI

rivo logotview

Terminal UI library with rich, interactive widgets — written in Golang

10,669
557
10,669
109

Top Related Projects

4,521

Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.

9,827

Minimalist Go package aimed at creating Console User Interfaces.

13,132

Golang terminal dashboard

2,091

A UI library for terminal applications.

Pure Go termbox implementation

26,628

A powerful little TUI framework 🏗

Quick Overview

rivo/tview is a rich interactive widgets library for terminal-based user interfaces in Go. It provides a flexible and powerful set of components for building text-based applications with advanced features like mouse support, color, and flexible layouts.

Pros

  • Rich set of pre-built widgets and layouts for rapid development
  • Supports both keyboard and mouse input
  • Flexible and customizable, allowing for complex UI designs
  • Cross-platform compatibility

Cons

  • Learning curve for developers new to terminal-based UIs
  • Limited to text-based interfaces, not suitable for graphical applications
  • May require additional effort for accessibility features
  • Performance can be impacted with very large or complex layouts

Code Examples

Creating a simple application with a text view:

package main

import (
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()
    textView := tview.NewTextView().
        SetText("Hello, world!").
        SetTextAlign(tview.AlignCenter).
        SetTextColor(tcell.ColorGreen)
    if err := app.SetRoot(textView, true).Run(); err != nil {
        panic(err)
    }
}

Creating a form with input fields:

package main

import (
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()
    form := tview.NewForm().
        AddInputField("Name", "", 20, nil, nil).
        AddPasswordField("Password", "", 20, '*', nil).
        AddButton("Submit", func() {
            app.Stop()
        })
    if err := app.SetRoot(form, true).Run(); err != nil {
        panic(err)
    }
}

Creating a flex layout with multiple widgets:

package main

import (
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()
    flex := tview.NewFlex().
        AddItem(tview.NewBox().SetBorder(true).SetTitle("Left"), 0, 1, false).
        AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
            AddItem(tview.NewBox().SetBorder(true).SetTitle("Top"), 0, 1, false).
            AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom"), 0, 1, false), 0, 2, false).
        AddItem(tview.NewBox().SetBorder(true).SetTitle("Right"), 0, 1, false)
    if err := app.SetRoot(flex, true).Run(); err != nil {
        panic(err)
    }
}

Getting Started

To use rivo/tview in your Go project:

  1. Install the library:

    go get github.com/rivo/tview
    
  2. Import it in your Go file:

    import "github.com/rivo/tview"
    
  3. Create an application and add widgets:

    app := tview.NewApplication()
    // Add widgets and set up your UI
    if err := app.Run(); err != nil {
        panic(err)
    }
    

Competitor Comparisons

4,521

Tcell is an alternate terminal package, similar in some ways to termbox, but better in others.

Pros of tcell

  • Lower-level library, offering more fine-grained control over terminal operations
  • Supports a wider range of terminal types and platforms
  • Generally faster performance due to its lower-level nature

Cons of tcell

  • Requires more code to create complex user interfaces
  • Steeper learning curve for developers new to terminal-based UIs
  • Less built-in support for high-level UI components

Code comparison

tcell (basic screen setup):

screen, err := tcell.NewScreen()
if err != nil {
    log.Fatal(err)
}
screen.Init()

tview (basic application setup):

app := tview.NewApplication()
box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
if err := app.SetRoot(box, true).Run(); err != nil {
    panic(err)
}

tview is built on top of tcell, providing a higher-level abstraction for creating terminal user interfaces. While tcell offers more control and flexibility, tview simplifies the process of building complex UIs with pre-built components and layouts. tcell is better suited for projects requiring low-level terminal manipulation, while tview is ideal for rapidly developing feature-rich terminal applications with less code.

9,827

Minimalist Go package aimed at creating Console User Interfaces.

Pros of gocui

  • Simpler API with fewer abstractions, making it easier to get started
  • More low-level control over the terminal UI elements
  • Smaller codebase, potentially easier to understand and modify

Cons of gocui

  • Less feature-rich compared to tview
  • Fewer built-in widgets and layout options
  • Less active development and community support

Code Comparison

gocui example:

g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
    log.Panicln(err)
}
defer g.Close()

g.SetManagerFunc(layout)

tview example:

app := tview.NewApplication()
box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
if err := app.SetRoot(box, true).Run(); err != nil {
    panic(err)
}

Both libraries provide ways to create terminal user interfaces in Go, but tview offers a higher-level API with more built-in widgets and layout options. gocui provides more low-level control but requires more manual setup. tview is generally more feature-rich and actively maintained, while gocui offers a simpler approach for basic terminal UIs.

13,132

Golang terminal dashboard

Pros of termui

  • More visually appealing and feature-rich widgets, including charts and graphs
  • Better suited for data visualization and dashboard-style applications
  • Supports mouse input for interactive elements

Cons of termui

  • Less actively maintained, with fewer recent updates
  • More complex API, potentially steeper learning curve
  • Limited flexibility for custom layouts compared to tview

Code Comparison

termui example:

p := widgets.NewParagraph()
p.Text = "Hello World!"
p.SetRect(0, 0, 25, 5)

ui.Render(p)

tview example:

app := tview.NewApplication()
text := tview.NewTextView().SetText("Hello World!")
app.SetRoot(text, true).Run()

Both libraries offer ways to create terminal user interfaces in Go, but they cater to different use cases. termui excels in creating visually rich dashboards and data visualizations, while tview provides a more flexible and customizable approach for general-purpose terminal applications. The choice between them depends on the specific requirements of your project and the level of control you need over the UI elements.

2,091

A UI library for terminal applications.

Pros of tui-go

  • Simpler API with fewer concepts to learn
  • More flexible layout system using constraints
  • Better support for custom widgets and drawing

Cons of tui-go

  • Less actively maintained (last commit in 2019)
  • Fewer built-in widgets compared to tview
  • Limited documentation and examples

Code Comparison

tui-go example:

box := tui.NewVBox(
    tui.NewLabel("Hello, world!"),
    tui.NewLabel("Press q to quit"),
)

ui, err := tui.New(box)
if err != nil {
    log.Fatal(err)
}

tview example:

box := tview.NewBox().
    SetBorder(true).
    SetTitle("Hello, world!")

app := tview.NewApplication().
    SetRoot(box, true)

if err := app.Run(); err != nil {
    panic(err)
}

Both libraries provide ways to create terminal user interfaces in Go, but tview offers a more extensive set of widgets and is actively maintained. tui-go has a simpler API and more flexible layout system, but lacks recent updates and comprehensive documentation. tview is generally considered more feature-rich and better supported, making it a more popular choice for complex TUI applications in Go.

Pure Go termbox implementation

Pros of termbox-go

  • Lower-level API, offering more fine-grained control over terminal output
  • Lightweight and minimal dependencies, suitable for simple terminal applications
  • Cross-platform support with consistent behavior across different operating systems

Cons of termbox-go

  • Less feature-rich compared to tview, requiring more manual implementation of UI elements
  • Steeper learning curve for creating complex terminal user interfaces
  • Limited built-in support for advanced text formatting and styling

Code Comparison

termbox-go:

termbox.Init()
defer termbox.Close()
termbox.SetCell(0, 0, 'H', termbox.ColorDefault, termbox.ColorDefault)
termbox.Flush()

tview:

app := tview.NewApplication()
box := tview.NewBox().SetBorder(true).SetTitle("Hello, World!")
app.SetRoot(box, true).Run()

The code comparison demonstrates that tview provides a higher-level abstraction for creating UI elements, while termbox-go requires more manual handling of individual cells and screen updates. tview's approach is more suitable for complex applications, while termbox-go offers greater flexibility for simpler use cases.

26,628

A powerful little TUI framework 🏗

Pros of Bubbletea

  • More flexible and composable architecture, allowing for easier creation of complex UIs
  • Better support for modern Go practices, including context usage and error handling
  • Extensive ecosystem of components and tools (Bubbles, Lip Gloss, etc.)

Cons of Bubbletea

  • Steeper learning curve, especially for developers new to functional programming concepts
  • Less out-of-the-box widgets compared to Tview, requiring more custom implementation

Code Comparison

Bubbletea example:

type model struct{}

func (m model) Init() tea.Cmd { return nil }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
func (m model) View() string { return "Hello, World!" }

Tview example:

app := tview.NewApplication()
text := tview.NewTextView().SetText("Hello, World!")
if err := app.SetRoot(text, true).Run(); err != nil {
    panic(err)
}

Bubbletea uses a more functional approach with a model and update cycle, while Tview follows a more traditional object-oriented style with widgets and layouts. Bubbletea's architecture allows for more complex state management, while Tview provides a simpler API for basic UI components.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Rich Interactive Widgets for Terminal UIs

PkgGoDev Go Report

This Go package provides commonly used components for terminal based user interfaces.

Screenshot

Among these components are:

  • Input forms (including text input, selections, checkboxes, and buttons)
  • Navigable multi-color text views
  • Editable multi-line text areas
  • Sophisticated navigable table views
  • Flexible tree views
  • Selectable lists
  • Images
  • Grid, Flexbox and page layouts
  • Modal message windows
  • An application wrapper

They come with lots of customization options and can be easily extended to fit your needs.

Usage

To add this package to your project:

go get github.com/rivo/tview@master

Hello World

This basic example creates a box titled "Hello, World!" and displays it in 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)
	}
}

Check out the GitHub Wiki for more examples along with screenshots. Or try the examples in the "demos" subdirectory.

For a presentation highlighting this package, compile and run the program found in the "demos/presentation" subdirectory.

Projects using tview

Documentation

Refer to https://pkg.go.dev/github.com/rivo/tview for the package's documentation. Also check out the Wiki.

Dependencies

This package is based on github.com/gdamore/tcell (and its dependencies) as well as on github.com/rivo/uniseg.

Sponsor this Project

Become a Sponsor on GitHub to further this project!

Versioning and Backwards-Compatibility

I try really hard to keep this project backwards compatible. Your software should not break when you upgrade tview. But this also means that some of its shortcomings that were present in the initial versions will remain. In addition, at least for the time being, you won't find any version tags in this repo. The newest version should be the one to upgrade to. It has all the bugfixes and latest features. Having said that, backwards compatibility may still break when:

  • a new version of an imported package (most likely tcell) changes in such a way that forces me to make changes in tview as well,
  • I fix something that I consider a bug, rather than a feature, something that does not work as originally intended,
  • I make changes to "internal" interfaces such as Primitive. You shouldn't need these interfaces unless you're writing your own primitives for tview. (Yes, I realize these are public interfaces. This has advantages as well as disadvantages. For the time being, it is what it is.)

Your Feedback

Add your issue here on GitHub. Feel free to get in touch if you have any questions.

Code of Conduct

We follow Golang's Code of Conduct which you can find here.