~/Golang TUI Development Quick Guide

Sep 15, 2020


Text user interfaces, or TUIs, let you create fast and interactive console applications. Golang offers several libraries, including tview and termui, to speed up development.

Install tview:

1
go get github.com/rivo/tview

Basic tview example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
package main

import "github.com/rivo/tview"

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

You can add forms, tables, or trees. For advanced layouts, use Flex.

To render gauges, charts, or dashboards, check termui.

Summary:

Stick to standard input and output for compatibility with all terminals. For more details and community examples, see the Awesome Go TUI list.

Tags: [golang] [tui] [cli]