Convert Figma logo to code with AI

marcusolsson logotui-go

A UI library for terminal applications.

2,091
122
2,091
30

Top Related Projects

10,669

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

9,827

Minimalist Go package aimed at creating Console User Interfaces.

4,521

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

13,132

Golang terminal dashboard

Pure Go termbox implementation

26,628

A powerful little TUI framework 🏗

Quick Overview

tui-go is a Go library for building text-based user interfaces (TUIs) in terminal applications. It provides a declarative approach to creating rich, interactive terminal UIs with a focus on simplicity and ease of use.

Pros

  • Simple and intuitive API for creating terminal UIs
  • Cross-platform compatibility (works on Windows, macOS, and Linux)
  • Supports various UI elements like buttons, text inputs, and lists
  • Flexible layout system for organizing UI components

Cons

  • Limited documentation and examples compared to some other TUI libraries
  • Not as feature-rich as some alternatives (e.g., tcell or termui)
  • Less active development and community support

Code Examples

  1. Creating a simple label:
package main

import (
    "github.com/marcusolsson/tui-go"
)

func main() {
    label := tui.NewLabel("Hello, World!")
    ui, err := tui.New(label)
    if err != nil {
        panic(err)
    }
    ui.Run()
}
  1. Creating a button with an action:
button := tui.NewButton("Click me!")
button.OnActivated(func(b *tui.Button) {
    b.SetLabel("Clicked!")
})
  1. Creating a text input:
input := tui.NewEntry()
input.SetFocused(true)
input.SetSizePolicy(tui.Expanding, tui.Maximum)
  1. Creating a vertical box layout:
box := tui.NewVBox(
    tui.NewLabel("First item"),
    tui.NewLabel("Second item"),
    tui.NewLabel("Third item"),
)

Getting Started

To use tui-go in your Go project, follow these steps:

  1. Install the library:

    go get github.com/marcusolsson/tui-go
    
  2. Import the library in your Go code:

    import "github.com/marcusolsson/tui-go"
    
  3. Create a simple UI:

    package main
    
    import (
        "github.com/marcusolsson/tui-go"
    )
    
    func main() {
        root := tui.NewVBox(
            tui.NewLabel("Welcome to tui-go!"),
            tui.NewButton("Quit"),
        )
    
        ui, err := tui.New(root)
        if err != nil {
            panic(err)
        }
    
        ui.SetKeybinding("Esc", func() { ui.Quit() })
    
        if err := ui.Run(); err != nil {
            panic(err)
        }
    }
    

This example creates a simple UI with a label and a button, and sets up a keybinding to quit the application when the Esc key is pressed.

Competitor Comparisons

10,669

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

Pros of tview

  • More actively maintained with frequent updates
  • Richer set of widgets and layout options
  • Better documentation and examples

Cons of tview

  • Steeper learning curve due to more complex API
  • Larger codebase, potentially impacting performance

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:

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

Both libraries offer similar functionality for creating terminal user interfaces in Go. tview provides a more comprehensive set of features and is actively maintained, making it a popular choice for complex TUI applications. However, tui-go may be simpler to get started with for basic interfaces. The code examples demonstrate the slight differences in API design, with tview using a more object-oriented approach and tui-go favoring a more functional style.

9,827

Minimalist Go package aimed at creating Console User Interfaces.

Pros of gocui

  • More mature and stable project with a larger community and more contributors
  • Provides lower-level control over the terminal UI, allowing for more customization
  • Better suited for complex, multi-window applications

Cons of gocui

  • Steeper learning curve due to its lower-level API
  • Requires more boilerplate code to set up basic UI elements
  • Less intuitive for beginners compared to tui-go's higher-level abstractions

Code Comparison

gocui example:

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

g.SetManagerFunc(layout)

tui-go example:

root := tui.NewVBox(
    tui.NewLabel("Hello, world!"),
    tui.NewSpacer(),
)
ui, err := tui.New(root)
if err != nil {
    log.Fatal(err)
}

Both libraries offer powerful tools for creating terminal user interfaces in Go. gocui provides more fine-grained control and is better suited for complex applications, while tui-go offers a higher-level API that's easier to get started with for simpler UIs. The choice between them depends on the specific requirements of your project and your familiarity with terminal UI concepts.

4,521

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

Pros of tcell

  • More mature and widely used project with a larger community
  • Supports a broader range of terminal types and platforms
  • Offers lower-level control over terminal input and output

Cons of tcell

  • Steeper learning curve due to its lower-level nature
  • Requires more code to create complex UI layouts compared to tui-go

Code Comparison

tcell example:

screen, _ := tcell.NewScreen()
screen.Init()
defer screen.Fini()

screen.SetContent(0, 0, 'H', nil, tcell.StyleDefault)
screen.Show()

tui-go example:

root := tui.NewHBox(
    tui.NewLabel("Hello, world!"),
)
ui, _ := tui.New(root)
ui.Run()

Summary

tcell is a lower-level library offering more control and wider platform support, while tui-go provides a higher-level abstraction for creating terminal UIs with less code. tcell is better suited for complex, custom terminal applications, whereas tui-go is ideal for quickly building simple terminal UIs with pre-defined widgets.

13,132

Golang terminal dashboard

Pros of termui

  • More feature-rich with a wider variety of UI components and widgets
  • Better suited for data visualization with built-in charts and graphs
  • More active development and larger community support

Cons of termui

  • Steeper learning curve due to more complex API
  • Less flexible layout system compared to tui-go's constraint-based approach
  • Heavier dependency footprint

Code Comparison

tui-go example:

box := tui.NewHBox(
    tui.NewLabel("Hello"),
    tui.NewLabel("World!"),
)
ui, err := tui.New(box)
if err != nil {
    log.Fatal(err)
}
ui.Run()

termui example:

p := widgets.NewParagraph()
p.Text = "Hello World!"
p.SetRect(0, 0, 25, 5)
ui.Render(p)
uiEvents := ui.PollEvents()
for {
    e := <-uiEvents
    if e.Type == ui.KeyboardEvent {
        break
    }
}

Both libraries offer TUI creation capabilities in Go, but they differ in their approach and feature set. tui-go provides a simpler, more intuitive API with a flexible layout system, making it easier for beginners to get started. termui, on the other hand, offers a wider range of pre-built widgets and better support for data visualization, but with a steeper learning curve. The choice between the two depends on the specific requirements of your project and your familiarity with TUI development.

Pure Go termbox implementation

Pros of termbox-go

  • Lower-level API, offering more fine-grained control over terminal output
  • Lighter weight and potentially faster performance
  • Wider platform support, including Windows

Cons of termbox-go

  • Less feature-rich compared to tui-go's higher-level widgets
  • Requires more manual work to create complex UI layouts
  • Limited built-in support for styling and theming

Code Comparison

termbox-go example:

termbox.Init()
defer termbox.Close()

termbox.SetCell(10, 10, 'H', termbox.ColorDefault, termbox.ColorDefault)
termbox.Flush()

tui-go example:

box := tui.NewHBox(
    tui.NewLabel("Hello, world!"),
)
ui, err := tui.New(box)
if err != nil {
    log.Fatal(err)
}
ui.Run()

Summary

termbox-go provides a lower-level API for terminal manipulation, offering more control but requiring more manual work. tui-go, on the other hand, provides higher-level widgets and abstractions, making it easier to create complex UIs but potentially sacrificing some flexibility and performance. The choice between the two depends on the specific requirements of your project and the level of control you need over the terminal interface.

26,628

A powerful little TUI framework 🏗

Pros of Bubbletea

  • More active development and community support
  • Built-in support for keyboard input and mouse events
  • Simpler API with a focus on functional programming concepts

Cons of Bubbletea

  • Steeper learning curve for developers unfamiliar with functional programming
  • Less comprehensive documentation compared to tui-go

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)
}

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!\nPress q to quit."
}

Both libraries offer ways to create terminal user interfaces in Go, but they differ in their approach and syntax. tui-go uses a more traditional object-oriented style, while Bubbletea embraces functional programming concepts with its Model-View-Update architecture. Bubbletea's approach may be more appealing to developers familiar with functional programming, while tui-go might be easier for those coming from an object-oriented background.

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

tui: Terminal UI for Go

Build Status GoDoc Go Report Card License MIT

A UI library for terminal applications.

tui (pronounced tooey) provides a higher-level programming model for building rich terminal applications. It lets you build layout-based user interfaces that (should) gracefully handle resizing for you.

IMPORTANT: tui-go is still in an experimental phase so please don't use it for anything other than experiments, yet.

Update: I created tui-go as an experiment because I wanted a simpler way of creating terminal-based user interfaces. It has since then become a project, with all the work that comes with it. While it's been really fun, unfortunately I'm no longer able to maintain this project.

Since I started working on tui-go, a number of similar projects have popped up. One that I think shows great promise is rivo/tview, which embodies much of what I envisioned for tui-go. I highly recommend trying it out!

Thanks all of you who have contributed and supported tui-go!

Screenshot

Installation

go get github.com/marcusolsson/tui-go

Usage

package main

import "github.com/marcusolsson/tui-go"

func main() {
	box := tui.NewVBox(
		tui.NewLabel("tui-go"),
	)

	ui, err := tui.New(box)
	if err != nil {
		panic(err)
	}
	ui.SetKeybinding("Esc", func() { ui.Quit() })

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

Getting started

If you want to know what it is like to build terminal applications with tui-go, check out some of the examples.

Documentation is available at godoc.org.

Make sure you check out some of the projects using tui-go.

Once you've gotten started developing your first application with tui-go, you might be interested in learning about common patterns or how you can debug your applications.

Related projects

tui-go is mainly influenced by Qt and offers a similar programming model that has been adapted to Go and the terminal.

For an overview of the alternatives for writing terminal user interfaces, check out this article by AppliedGo.

License

tui-go is released under the MIT License.

Contact

If you're interested in chatting with users and contributors, join #tui-go on the Gophers Slack. If you're not already a part of the Slack workspace, you can join here. If you prefer a lower-bandwidth interface, see this article on connecting to Slack via IRC or XMPP.