Alkorin/gotui

Lightweight Go package for creating terminal user interfaces

★ 0Forks 0GoGitHub ↗Compare

README

GOTUI - Go Terminal User Interface

GoDoc

Lightweight Go package for creating terminal user interfaces based on gocui

Features

  • Minimalist API.
  • Views (the "windows" in the GUI) implement the interface io.ReadWriter.
  • Support for overlapping views.
  • The GUI can be modified at runtime (concurrent-safe).
  • Global and view-level keybindings.
  • Mouse support.
  • Colored text.
  • Customizable edition mode.
  • Easy to build reusable widgets, complex layouts...

Installation

Execute:

$ go get github.com/makyo/gotui

Documentation

Execute:

$ go doc github.com/makyo/gotui

Or visit godoc.org to read it online.

Example

package main

import (
	"fmt"
	"log"

	"github.com/makyo/gotui"
)

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

	g.SetManagerFunc(layout)

	if err := g.SetKeybinding("", gotui.KeyCtrlC, gotui.ModNone, quit); err != nil {
		log.Panicln(err)
	}

	if err := g.MainLoop(); err != nil && err != gotui.ErrQuit {
		log.Panicln(err)
	}
}

func layout(g *gotui.Gui) error {
	maxX, maxY := g.Size()
	if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
		if err != gotui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, "Hello world!")
	}
	return nil
}

func quit(g *gotui.Gui, v *gotui.View) error {
	return gotui.ErrQuit
}

More information

For more information, please see the lovely gocui package this was based on.

Contributors

jroimartinmakyogulyasmdjcas9JulienBreuxalitariaskovpencswankdtylmangbittenhassansinheppuJameskmongermiguelmotamkchoi212rlisagorKayoticSullyZaba505govlastelecoda

Issues