Golang terminal dashboard
Switch branches/tags
Clone or download
Latest commit fede2b0 Sep 15, 2018
Permalink
Failed to load latest commit information.
_docs Add readthedocs Doc Mar 9, 2016
_examples Readd explicit error handling to examples Sep 7, 2018
debug Fix #97 May 2, 2017
extra add missing characters Jul 17, 2017
scripts File renaming Sep 6, 2018
test Update copyright Jan 14, 2017
.gitignore Remove panicparse Sep 6, 2018
.travis.yml Update travis config Mar 20, 2015
Gopkg.lock Remove panicparse Sep 6, 2018
Gopkg.toml Remove panicparse Sep 6, 2018
LICENSE Initial commit Feb 3, 2015
README.md Update README and fix _examples links Sep 6, 2018
barchart.go Minor refactor Sep 6, 2018
block.go Minor refactor Sep 6, 2018
block_common.go Update copyright Jan 14, 2017
block_test.go Minor refactor Sep 6, 2018
block_windows.go add missing characters Jul 17, 2017
buffer.go Update copyright Jan 14, 2017
buffer_test.go Update copyright Jan 14, 2017
canvas.go Update copyright Jan 14, 2017
canvas_test.go Update copyright Jan 14, 2017
doc.go Update copyright Jan 14, 2017
events.go Add <Mouse> and <Keyboard> events Sep 15, 2018
events_test.go Update copyright Jan 14, 2017
gauge.go Minor refactor Sep 6, 2018
grid.go spelling: implements Mar 14, 2016
grid_test.go Update copyright Jan 14, 2017
helper.go Minor refactor Sep 6, 2018
helper_test.go Update copyright Jan 14, 2017
linechart.go Minor refactor Sep 6, 2018
linechart_others.go Update copyright Jan 14, 2017
linechart_windows.go Update copyright Jan 14, 2017
list.go Minor refactor Sep 6, 2018
mbarchart.go Minor refactor Sep 6, 2018
mkdocs.yml Add readthedocs Doc Mar 9, 2016
par.go Update copyright Jan 14, 2017
par_test.go Update copyright Jan 14, 2017
piechart.go Cleanup piechart Aug 17, 2018
pos.go Update copyright Jan 14, 2017
pos_test.go Update copyright Jan 14, 2017
render.go Rework event system Sep 6, 2018
sparkline.go Minor refactor Sep 6, 2018
table.go Minor refactor Sep 6, 2018
textbuilder.go 256 color support Aug 17, 2018
textbuilder_test.go Update copyright Jan 14, 2017
theme.go Minor refactor Sep 6, 2018
theme_test.go Update copyright Jan 14, 2017
widget.go Rework event system Sep 6, 2018

README.md

termui Build Status Doc Status

demo cast under osx 10.10; Terminal.app; Menlo Regular 12pt.)

termui is a cross-platform, easy-to-compile, and fully-customizable terminal dashboard. It is inspired by blessed-contrib, but purely in Go.

Now version v2 has arrived! It brings new event system, new theme system, new Buffer interface and specific colour text rendering. (some docs are missing, but it will be completed soon!)

Installation

master mirrors v2 branch, to install:

go get -u github.com/gizak/termui

It is recommanded to use locked deps by using dep: move to termui src directory then run dep ensure.

For the compatible reason, you can choose to install the legacy version of termui:

go get gopkg.in/gizak/termui.v1

Usage

Layout

To use termui, the very first thing you may want to know is how to manage layout. termui offers two ways of doing this, known as absolute layout and grid layout.

Absolute layout

Each widget has an underlying block structure which basically is a box model. It has border, label and padding properties. A border of a widget can be chosen to hide or display (with its border label), you can pick a different front/back colour for the border as well. To display such a widget at a specific location in terminal window, you need to assign .X, .Y, .Height, .Width values for each widget before sending it to .Render. Let's demonstrate these by a code snippet:

	import ui "github.com/gizak/termui" // <- ui shortcut, optional

	func main() {
		err := ui.Init()
		if err != nil {
			panic(err)
		}
		defer ui.Close()

		p := ui.NewPar(":PRESS q TO QUIT DEMO")
		p.Height = 3
		p.Width = 50
		p.TextFgColor = ui.ColorWhite
		p.BorderLabel = "Text Box"
		p.BorderFg = ui.ColorCyan

		g := ui.NewGauge()
		g.Percent = 50
		g.Width = 50
		g.Height = 3
		g.Y = 11
		g.BorderLabel = "Gauge"
		g.BarColor = ui.ColorRed
		g.BorderFg = ui.ColorWhite
		g.BorderLabelFg = ui.ColorCyan

		ui.Render(p, g) // feel free to call Render, it's async and non-block

		// event handler...
	}

Note that components can be overlapped (I'd rather call this a feature...), Render(rs ...Renderer) renders its args from left to right (i.e. each component's weight is arising from left to right).

Grid layout:

grid

Grid layout uses 12 columns grid system with expressive syntax. To use Grid, all we need to do is build a widget tree consisting of Rows and Cols (Actually a Col is also a Row but with a widget endpoint attached).

	import ui "github.com/gizak/termui"
	// init and create widgets...

	// build
	ui.Body.AddRows(
		ui.NewRow(
			ui.NewCol(6, 0, widget0),
			ui.NewCol(6, 0, widget1)),
		ui.NewRow(
			ui.NewCol(3, 0, widget2),
			ui.NewCol(3, 0, widget30, widget31, widget32),
			ui.NewCol(6, 0, widget4)))

	// calculate layout
	ui.Body.Align()

	ui.Render(ui.Body)

Events

termui ships with a http-like event mux handling system. All events are channeled up from different sources (typing, click, windows resize, custom event) and then encoded as universal Event object. Event.Path indicates the event type and Event.Data stores the event data struct. Add a handler to a certain event is easy as below:

	// handle key q pressing
	ui.Handle("/sys/kbd/q", func(ui.Event) {
		// press q to quit
		ui.StopLoop()
	})

	ui.Handle("/sys/kbd/C-x", func(ui.Event) {
		// handle Ctrl + x combination
	})

	ui.Handle("/sys/kbd", func(ui.Event) {
		// handle all other key pressing
	})

	// handle a 1s timer
	ui.Handle("/timer/1s", func(e ui.Event) {
		t := e.Data.(ui.EvtTimer)
		// t is a EvtTimer
		if t.Count%2 ==0 {
			// do something
		}
	})

	ui.Loop() // block until StopLoop is called

Widgets

Click image to see the corresponding demo codes.

par list gauge linechart barchart barchart sparklines table

GoDoc

godoc

TODO

  • Grid layout
  • Event system
  • Canvas widget
  • Refine APIs
  • Focusable widgets

Changelog

License

This library is under the MIT License