gocui/README.md

98 lines
2.2 KiB
Markdown
Raw Normal View History

# GOCUI - Go Console User Interface
2013-12-27 21:36:26 +01:00
2016-02-01 15:36:10 +01:00
[![GoDoc](https://godoc.org/github.com/jroimartin/gocui?status.svg)](https://godoc.org/github.com/jroimartin/gocui)
2014-01-28 09:36:57 +01:00
Minimalist Go package aimed at creating Console User Interfaces.
2014-01-04 03:48:48 +01:00
2015-01-24 14:35:23 +01:00
## Features
2014-01-19 17:42:51 +01:00
2014-01-28 09:36:57 +01:00
* Minimalist API.
* Views (the "windows" in the GUI) implement the interface io.ReadWriter.
2014-01-28 09:36:57 +01:00
* Support for overlapping views.
* The GUI can be modified at runtime (concurrent-safe).
2014-01-28 09:36:57 +01:00
* Global and view-level keybindings.
* Mouse support.
2016-04-28 01:22:15 +02:00
* Colored text.
* Customizable edition mode.
## Installation
2016-02-01 15:36:10 +01:00
Execute:
```
2016-02-01 15:39:59 +01:00
$ go get github.com/jroimartin/gocui
2016-02-01 15:36:10 +01:00
```
## Documentation
Execute:
2016-02-01 15:36:10 +01:00
```
2016-10-03 11:15:42 +02:00
$ go doc github.com/jroimartin/gocui
2016-02-01 15:36:10 +01:00
```
2016-02-01 15:39:59 +01:00
Or visit [godoc.org](https://godoc.org/github.com/jroimartin/gocui) to read it
online.
2014-01-28 09:36:57 +01:00
2015-01-24 14:35:23 +01:00
## Example
```go
package main
import (
"fmt"
"log"
"github.com/jroimartin/gocui"
)
2015-01-24 14:35:23 +01:00
func main() {
2016-10-24 07:26:59 +02:00
g, err := gocui.NewGui()
if err != nil {
2015-01-24 14:35:23 +01:00
log.Panicln(err)
2014-01-19 17:42:51 +01:00
}
2015-01-24 14:35:23 +01:00
defer g.Close()
2015-01-24 14:35:23 +01:00
g.SetLayout(layout)
2015-01-24 14:35:23 +01:00
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
2015-01-24 14:35:23 +01:00
log.Panicln(err)
2014-01-19 17:42:51 +01:00
}
2015-01-24 14:35:23 +01:00
}
func layout(g *gocui.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 != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "Hello world!")
}
return nil
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
```
2015-02-01 17:23:04 +01:00
## Screenshots
2016-10-16 18:54:00 +02:00
![r2cui](https://cloud.githubusercontent.com/assets/1223476/19418932/63645052-93ce-11e6-867c-da5e97e37237.png)
2015-02-01 17:23:04 +01:00
![_examples/demo.go](https://cloud.githubusercontent.com/assets/1223476/5992750/720b84f0-aa36-11e4-88ec-296fa3247b52.png)
![_examples/dynamic.go](https://cloud.githubusercontent.com/assets/1223476/5992751/76ad5cc2-aa36-11e4-8204-6a90269db827.png)
## Projects using gocui
* [Komanda CLI](https://github.com/mephux/komanda-cli): IRC Client For Developers.
* [Vuls](https://github.com/future-architect/vuls): Agentless vulnerability scanner for Linux/FreeBSD.
* [SumoLogic sumoshell](https://github.com/SumoLogic/sumoshell): Terminal-only version of Sumo.
Note: if your project is not listed here, let us know! :)