README.md

 1# GOCUI - Go Console User Interface
 2
 3[![GoDoc](https://godoc.org/github.com/jroimartin/gocui?status.svg)](https://godoc.org/github.com/jroimartin/gocui)
 4
 5Minimalist Go package aimed at creating Console User Interfaces.
 6
 7## Features
 8
 9* Minimalist API.
10* Views (the "windows" in the GUI) implement the interface io.ReadWriter.
11* Support for overlapping views.
12* The GUI can be modified at runtime (concurrent-safe).
13* Global and view-level keybindings.
14* Mouse support.
15* Colored text.
16* Customizable edition mode.
17
18## Installation
19
20Execute:
21
22```
23$ go get github.com/jroimartin/gocui
24```
25
26## Documentation
27
28Execute:
29
30```
31$ go doc github.com/jroimartin/gocui
32```
33
34Or visit [godoc.org](https://godoc.org/github.com/jroimartin/gocui) to read it
35online.
36
37## Example
38
39```go
40package main
41
42import (
43	"fmt"
44	"log"
45
46	"github.com/jroimartin/gocui"
47)
48
49func main() {
50	g := gocui.NewGui()
51	if err := g.Init(); err != nil {
52		log.Panicln(err)
53	}
54	defer g.Close()
55
56	g.SetLayout(layout)
57
58	if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
59		log.Panicln(err)
60	}
61
62	if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
63		log.Panicln(err)
64	}
65}
66
67func layout(g *gocui.Gui) error {
68	maxX, maxY := g.Size()
69	if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
70		if err != gocui.ErrUnknownView {
71			return err
72		}
73		fmt.Fprintln(v, "Hello world!")
74	}
75	return nil
76}
77
78func quit(g *gocui.Gui, v *gocui.View) error {
79	return gocui.ErrQuit
80}
81```
82
83## Screenshots
84
85_examples/demo.go:
86
87![_examples/demo.go](https://cloud.githubusercontent.com/assets/1223476/5992750/720b84f0-aa36-11e4-88ec-296fa3247b52.png)
88
89_examples/dynamic.go:
90
91![_examples/dynamic.go](https://cloud.githubusercontent.com/assets/1223476/5992751/76ad5cc2-aa36-11e4-8204-6a90269db827.png)