A UI library for terminal applications.

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.

Comments
  • Scroll area support

    Scroll area support

    Tables with too many rows will not fit. When a row outside view is selected the scroll area should offset the view to include the selected row.

    For comparison: Qt has a QScrollArea that decorates a widget with scrolling functionality.

    This would be very nice combined with mouse support :)

    Example:

    t := tui.NewTable(0,0)
    a := tui.NewScrollArea(t)
    
  • Changing focus

    Changing focus

    User need to be able to change focus from one widget to another, e.g. between OK and Cancel buttons.

    tui should be able to construct a default focus chain that can be overrided.

    Cycling widgets should probably be done with Tab and Shift-Tab.

  • SetKeyBinding with ModCtrl + rune

    SetKeyBinding with ModCtrl + rune

    Hi, is it already possible to add keybindings with the ModKeys?

    If so I can't figure how from the docs and examples.

    I see SetKeybinding takes (inter{}, func ).

    How are ModKey events handled?

  • Spacer doesn't render background color

    Spacer doesn't render background color

    I've got a panel in my app that I'd like to draw with reversed colors. The way I've come up with to handle this is to embed the tui.Box in a custom struct, and override Draw with a custom function:

    func (c *custom) Draw(p *tui.Painter) {
      p.WithStyle("reversed", c.Box.Draw)
    }
    

    But, this doesn't work if the Box contains Spacer widgets - which still render using the default background. I'd expect them to be filled with the current background color, if I'm understanding the intended semantics of Draw and WithStyle correctly. (Is that the intended behavior?)

    Full example gist; I'm expecting a line across the whole thing.

    It looks like Spacer inherits the default WidgetBase Draw function, which is blank. I'm not sure if the default Draw should fill its background, or whether this should just apply to Spacer; I see #45 has a maybe-related commentary on Box.

    (All that said, tui is great to work with; looking forward to its future. :-) )

  • Swapping/Toggling UI components

    Swapping/Toggling UI components

    I'm looking to have 2 different components that can be toggled, where they both occupy the same space (a bit like a tabbed interface would). Is this currently achievable? I didn't notice show/hide methods on widget so assumed not.

  • Allow for removing a single item from a list

    Allow for removing a single item from a list

    List items can be added but not removed. Since the items are a simple []string a Clear() method would be a fairly straight forward approach, knowing items will have to be re-added if only one item is being cleared.

  • Make testSurface public

    Make testSurface public

    painter_test.go has a nice implementation of the Surface interface for testing writes.

    It would be nice to factor that out so tui users can test their own layouts or custom Widgets.

  • Add scroll area

    Add scroll area

    I think I finally got this nailed down. Issues were mostly related to masking rather than the scroll area itself. More specifically due to not having clearly defined what a zero mask meant.

    A key insight was to make sure that a mask needs to be defined at the root level, based on the size of the Surface.

    Closes #40.

  • Color support question

    Color support question

    First sorry if I bother you with so many questions!

    I'd like to have different font colors in my list ('ala tig tool) using something like https://github.com/fatih/color#insert-into-noncolor-strings-sprintfunc, e.g:

    // ...
    yellow := color.New(color.FgYellow).SprintFunc()
    red := color.New(color.FgRed).SprintFunc()
    return fmt.Sprintf("%s|%s|o %s", b.Author.When.String()[2:19], yellow(author), red(name))
    // then I use the returned string as en element for `list.AddItems()
    

    Unfortunately color codes are not rendered:

    screenshot 2017-06-06 23 13 43

    Any idea if this is possible? (-:

  • ScrollArea SizeHint uses underlying widget

    ScrollArea SizeHint uses underlying widget

    Hi! I'm not sure if this changed recently, because after updating the lib I found my scroll areas were only displaying 8 rows.

    The docs for the ScrollArea.SizeHint method suggest it is meant to return "the size hint of the underlying widget."

    This PR is doing just that 😄

  • Add a visual indicator on the box widget when b.IsFocused==true

    Add a visual indicator on the box widget when b.IsFocused==true

    ref #20

    I think this follow the direction given in the ticket. I had to increase the widget interface to add a method called IsFocused() bool.

    The example app works fine and looks ok except for the Login. For some reason the text SKYNET is also blue when the focus is on the buttons. I don't think it should be the case.

    There is still a bit of work but I would appreciate some feedback to let me know if I am on the right track.

    • [x] is the blue line to thick for the default the style box.selected if so how to decrease it ?
    • [x] Fix the login example
    • [x] write a test or 2
  • Archive the Project

    Archive the Project

    Hey! Just saw your project and noticed the "Update" in the readme.

    If you're no longer going to be maintaining the project, I'd recommend archiving it, unless you have a reason for keeping it active as it is currently.

    That's it.

    Thanks for putting your time and effort into something like this!

  • custom style for lists

    custom style for lists

    I've been writing a program which has many lists, for which the style is required to be different for some lists (highlighting can occur between lists)

    This PR basically, allows for a new "root" style of a list object to manually changed however still following the pattern of <yourstyle> for the default and <yourstyle>.selected for the selected box.

    This PR is backwards compatible with no interface changes

    Open to suggested design alternatives!

  • How do I create two tables with different selected styles?

    How do I create two tables with different selected styles?

    type TableEx struct {
    	*tui.Table
    
    	Style string
    }
    
    func (t *TableEx) Draw(p *tui.Painter) {
    	p.WithStyle(t.Style, func(p *tui.Painter) {
    		t.Table.Draw(p)
    	})
    }
    

    It just make custom table.cell style, but how do i replace the table.cell.selectedstytle?

  • Append to a tui.Box invalid

    Append to a tui.Box invalid

    This is my code:

    history.Append(tui.NewHBox(
    		tui.NewLabel(time.Now().Format("15:04")),
    		tui.NewPadder(1, 0, tui.NewLabel(fmt.Sprintf("<%s>", "john"))),
    		tui.NewLabel(message),
    		tui.NewSpacer(),
    	))
    

    In fact I am trying the "chat" example, and read data from a TCP connection, then write to the "history", but it not works.

  • CPU resources are not released after the app exits.

    CPU resources are not released after the app exits.

    Hello. I use your framework to develop a TUI file dialog, "tfd". This framework is great! But seems to have one bug. Apps created using this framework will not release CPU resources even if exit with ui.Quit().

    For example, if you put time.Sleep(time.Second*10) in the last line in tui-go/example/login/main.go, you can confirm that the CPU resources are not released.

    I don't know the details of this framework, but I thought this bug is caused by the for-loop in ui.Run() being kept running.

Dinogo is an CLI framework for build terminal and shell applications in Go.

dinogo Dinogo is an CLI framework for build terminal and shell applications in Go. Features Cross Platform Fast and efficient Keyboard API Enable/Disa

Aug 29, 2022
Source code of a YouTube tutorial about writing terminal applications with Golang

Bubble Tea Demo 00 Source code of a YouTube tutorial about writing terminal applications with Golang by using Bubble Tea. Contains a simple counter ap

Nov 10, 2022
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.

Stonks is a terminal based stock visualizer and tracker. Installation Requirements: golang >= 1.13 Manual Clone the repo Run make && make install Pack

Dec 16, 2022
A Go library for building command line applications

gocmd A Go library for building command line applications. Features Advanced command line arguments handling Subcommand handling Short and long comman

Dec 21, 2022
A versatile library for building CLI applications in Go

mow.cli Package cli provides a framework to build command line applications in Go with most of the burden of arguments parsing and validation placed o

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

Rich Interactive Widgets for Terminal UIs This Go package provides commonly needed components for terminal based user interfaces. Among these componen

Jan 7, 2023
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows.
🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows.

?? Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染

Dec 30, 2022
A Go library for terminal background color detection

go-termbg A Go library for terminal background color detection. The detected color is provided by RGB or theme ( dark or light ). Based on https://git

Jan 4, 2022
A very simple library for interactively selecting an option on a terminal
A very simple library for interactively selecting an option on a terminal

go-choice A very simple library for interactively selecting an option on a terminal Usage package main import ( "fmt" "github.com/TwiN/go-ch

Dec 30, 2021
Qalam - An easy to use terminal styling library
Qalam - An easy to use terminal styling library

Qalam ✏️ Qalam is a Go library for easy terminal styling. Installation go get gi

Jan 6, 2023
Simple and complete API for building command line applications in Go

Simple and complete API for building command line applications in Go Module cli provides a simple, fast and complete API for building command line app

Nov 23, 2022
An easy to use menu structure for cli applications that prompts users to make choices.
An easy to use menu structure for cli applications that prompts users to make choices.

WMenu Package wmenu creates menus for cli programs. It uses wlog for its interface with the command line. It uses os.Stdin, os.Stdout, and os.Stderr w

Dec 26, 2022
A really basic thread-safe progress bar for Golang applications
A really basic thread-safe progress bar for Golang applications

progressbar A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for croc and everything I tr

Jan 1, 2023
multi progress bar for Go cli applications

Multi Progress Bar mpb is a Go lib for rendering progress bars in terminal applications. Features Multiple Bars: Multiple progress bars are supported

Dec 28, 2022
Debug Dockerized Go applications better
Debug Dockerized Go applications better

A tool that makes debugging of Dockerized Go applications super easy by enabling Debugger and Hot-Reload features, seamlessly. Installing go get -u gi

Jan 4, 2023
Interactive prompt for command-line applications
Interactive prompt for command-line applications

promptui Interactive prompt for command-line applications. We built Promptui because we wanted to make it easy and fun to explore cloud services with

Jan 8, 2023
Jan 3, 2023
Teardown API for Commandline Based Applications
Teardown API for Commandline Based Applications

Building go build -ldflags "-s -w" -o ./build/api.exe ./ Get the latest XML from https://www.teardowngame.com/modding/api.xml Commands help list searc

Mar 1, 2022
Remove unwanted applications
Remove unwanted applications

I Don't Need This IDNT is a software uninstaller. Installation Download a binary from the release section. Usage Just run the tool, and you'll be pres

Dec 26, 2022