termui/README.md
2019-01-28 01:13:33 -08:00

2.7 KiB

termui

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

termui is a cross-platform and fully-customizable terminal dashboard and widget library built on top of termbox-go. It is inspired by blessed-contrib and tui-rs and written purely in Go.

Features

  • Built in widget implementations for common use cases
  • Utilities to create custom widgets
  • A grid layout for relative widget positioning
  • Mouse support
  • Event handling for keyboard, mouse and resizing events
  • Colors and styling

Hello World

package main

import (
	"log"

	ui "github.com/gizak/termui"
	"github.com/gizak/termui/widgets"
)

func main() {
	if err := ui.Init(); err != nil {
		log.Fatalf("failed to initialize termui: %v", err)
	}
	defer ui.Close()

	p := widgets.NewParagraph()
	p.Text = "Hello World!"
	p.SetRect(0, 0, 25, 5)

	ui.Render(p)

	for e := range ui.PollEvents() {
		if e.Type == ui.KeyboardEvent {
			break
		}
	}
}

Installation

Installing from the master branch is recommended. termui has been completely reworked since the latest release, and the latest release also doesn't support Go modules.

go get -u github.com/gizak/termui@master

Note: termui is currently undergoing API changes so make sure to check the changelog when upgrading. If you upgrade and notice something is missing or don't like a change, revert the upgrade and open an issue.

Widgets

Run an example with go run _examples/{example}.go or run all of them consecutively with make run-examples.

Documentation

Uses

License

MIT