2016-01-30 02:54:26 +01:00
|
|
|
# GOCUI - Go Console User Interface
|
2013-12-27 21:36:26 +01:00
|
|
|
|
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.
|
2016-01-30 02:54:26 +01:00
|
|
|
* Views (the "windows" in the GUI) implement the interface io.ReadWriter.
|
2014-01-28 09:36:57 +01:00
|
|
|
* Support for overlapping views.
|
2016-01-30 02:54:26 +01:00
|
|
|
* The GUI can be modified at runtime (concurrent-safe).
|
2014-01-28 09:36:57 +01:00
|
|
|
* Global and view-level keybindings.
|
2016-01-30 02:54:26 +01:00
|
|
|
* Mouse support.
|
|
|
|
* Customizable edition mode.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
`go get github.com/jroimartin/gocui`
|
|
|
|
|
2016-01-30 02:55:46 +01:00
|
|
|
## Documentation [](https://godoc.org/github.com/jroimartin/gocui)
|
2016-01-30 02:54:26 +01:00
|
|
|
|
2016-01-30 02:55:46 +01:00
|
|
|
`godoc github.com/jroimartin/gocui`
|
2014-01-28 09:36:57 +01:00
|
|
|
|
2015-01-24 14:35:23 +01:00
|
|
|
## Example
|
|
|
|
|
|
|
|
```go
|
2016-01-30 02:54:26 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
)
|
|
|
|
|
2015-01-24 14:35:23 +01:00
|
|
|
func main() {
|
|
|
|
g := gocui.NewGui()
|
|
|
|
if err := g.Init(); err != nil {
|
|
|
|
log.Panicln(err)
|
2014-01-19 17:42:51 +01:00
|
|
|
}
|
2015-01-24 14:35:23 +01:00
|
|
|
defer g.Close()
|
2016-01-30 02:54:26 +01:00
|
|
|
|
2015-01-24 14:35:23 +01:00
|
|
|
g.SetLayout(layout)
|
2016-01-30 02:54:26 +01:00
|
|
|
|
2015-01-24 14:35:23 +01:00
|
|
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
2016-01-30 02:54:26 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-01-26 10:19:11 +01:00
|
|
|
|
2016-01-30 02:54:26 +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
|
|
|
|
}
|
2016-01-26 10:19:11 +01:00
|
|
|
|
2016-01-30 02:54:26 +01:00
|
|
|
func quit(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gocui.ErrQuit
|
|
|
|
}
|
|
|
|
```
|
2016-01-26 10:19:11 +01:00
|
|
|
|
2015-02-01 17:23:04 +01:00
|
|
|
## Screenshots
|
|
|
|
|
2015-02-01 17:24:10 +01:00
|
|
|
_examples/demo.go:
|
2015-02-01 17:23:04 +01:00
|
|
|
|
|
|
|

|
|
|
|
|
2015-02-01 17:24:10 +01:00
|
|
|
_examples/delete.go:
|
2015-02-01 17:23:04 +01:00
|
|
|
|
|
|
|

|