Golang terminal dashboard
Go to file
gizak ab87ad72d1 Fix https://github.com/gizak/termui/issues/63 2015-12-06 12:51:37 -05:00
_example Fresh example screenshots 2015-10-28 21:19:35 -04:00
_extra Path adaption 2015-10-27 15:34:47 -04:00
debug Finish Event 2015-09-18 11:41:44 -04:00
test Add custom event handling 2015-10-13 12:45:03 -04:00
.gitignore Smash Border into Block 2015-04-26 00:13:49 -04:00
.travis.yml Update travis config 2015-03-20 13:06:29 -04:00
LICENSE Initial commit 2015-02-03 09:09:27 -05:00
README.md Fresh example screenshots 2015-10-28 21:19:35 -04:00
barchart.go Widgets API adaption 2015-10-08 22:11:26 -04:00
block.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
block_common.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
block_test.go Add Float prop 2015-10-13 01:00:15 -04:00
block_windows.go Smash Border into Block 2015-04-26 00:13:49 -04:00
buffer.go Fix grid demo and Buffer.Merge 2015-10-10 11:20:44 -04:00
buffer_test.go Fix grid demo and Buffer.Merge 2015-10-10 11:20:44 -04:00
canvas.go Widgets API adaption 2015-10-08 22:11:26 -04:00
canvas_test.go Fix grid demo and Buffer.Merge 2015-10-10 11:20:44 -04:00
doc.go Add docs 2015-03-24 17:16:43 -04:00
events.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
events_test.go Theme map lookup 2015-09-21 03:11:58 -04:00
gauge.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
grid.go Fix grid demo and Buffer.Merge 2015-10-10 11:20:44 -04:00
grid_test.go Adjust Grid test 2015-05-12 16:16:08 -04:00
helper.go Widgets API adaption 2015-10-08 22:11:26 -04:00
helper_test.go ColorSubsequence.Color is now an attribute 2015-04-10 16:57:42 +02:00
linechart.go Widgets API adaption 2015-10-08 22:11:26 -04:00
linechart_others.go Widgets API adaption 2015-10-08 22:11:26 -04:00
linechart_windows.go Widgets API adaption 2015-10-08 22:11:26 -04:00
list.go Widgets API adaption 2015-10-08 22:11:26 -04:00
mbarchart.go Widgets API adaption 2015-10-08 22:11:26 -04:00
par.go Widgets API adaption 2015-10-08 22:11:26 -04:00
par_test.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
pos.go Add Float prop 2015-10-13 01:00:15 -04:00
pos_test.go Add Float prop 2015-10-13 01:00:15 -04:00
render.go Fix https://github.com/gizak/termui/issues/63 2015-12-06 12:51:37 -05:00
sparkline.go Widgets API adaption 2015-10-08 22:11:26 -04:00
textbuilder.go Minor chanages 2015-05-09 19:29:22 -04:00
textbuilder_test.go Finish TextBuilder 2015-05-03 21:02:38 -04:00
theme.go Merge branch 'v2' 2015-10-22 11:17:20 -04:00
theme_test.go Theme map lookup 2015-09-21 03:11:58 -04:00
widget.go Add custom event handling 2015-10-13 12:45:03 -04:00

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

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 send 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.Border.Label = "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
	termui.Handle("/sys/kbd/q", func(termui.Event) {
		// press q to quit
		termui.StopLoop()
	})

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

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

	// handle a 1s timer
	termui.Handle("/timer/1s", func(e ui.Event) {
		t := e.Data.(termui.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

GoDoc

godoc

TODO

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

Changelog

License

This library is under the MIT License