termui/README.md

87 lines
3.0 KiB
Markdown
Raw Normal View History

2018-11-29 03:15:29 +00:00
# termui
2019-01-24 04:12:10 +00:00
<img src="./_assets/dashboard1.gif" alt="demo cast under osx 10.10; Terminal.app; Menlo Regular 12pt.)" width="100%">
2015-06-23 19:11:22 +00:00
2019-01-24 04:12:10 +00:00
termui is a cross-platform and fully-customizable terminal dashboard and widget library built on top of [termbox-go](https://github.com/nsf/termbox-go). It is inspired by [blessed-contrib](https://github.com/yaronn/blessed-contrib) and written purely in Go.
2018-11-29 05:13:29 +00:00
2015-10-27 19:24:29 +00:00
## Installation
2015-03-15 19:56:38 +00:00
2018-11-29 05:44:42 +00:00
Installing from the master branch is recommended:
2015-03-20 12:24:48 +00:00
2018-09-06 23:55:27 +00:00
```bash
2018-11-29 03:15:29 +00:00
go get -u github.com/gizak/termui@master
2018-09-06 23:55:27 +00:00
```
2015-03-20 12:24:48 +00:00
2019-01-24 04:12:10 +00:00
**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.
2015-10-27 19:24:29 +00:00
## Usage
2015-02-08 17:00:00 +00:00
2018-11-29 03:15:29 +00:00
### Hello World
2015-02-08 17:00:00 +00:00
2018-09-06 23:55:27 +00:00
```go
2018-11-29 04:12:36 +00:00
package main
2019-01-24 04:12:10 +00:00
import (
"log"
ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)
2015-02-08 17:00:00 +00:00
2018-11-29 03:15:29 +00:00
func main() {
2019-01-24 04:12:10 +00:00
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
2015-02-08 17:00:00 +00:00
}
2018-11-29 03:15:29 +00:00
defer ui.Close()
2019-01-24 04:12:10 +00:00
p := widgets.NewParagraph()
p.Text = "Hello World!"
p.SetRect(0, 0, 25, 5)
2018-11-29 03:15:29 +00:00
ui.Render(p)
2015-10-27 19:29:37 +00:00
2018-11-29 23:51:43 +00:00
for e := range ui.PollEvents() {
2018-11-29 18:22:51 +00:00
if e.Type == ui.KeyboardEvent {
2018-11-29 23:51:43 +00:00
break
2015-10-27 19:24:29 +00:00
}
2018-11-29 03:15:29 +00:00
}
}
2015-10-27 19:24:29 +00:00
```
2015-10-27 19:24:29 +00:00
### Widgets
2015-10-27 19:24:29 +00:00
Click image to see the corresponding demo codes.
2019-01-24 04:12:10 +00:00
[<img src="./_assets/barchart.png" alt="barchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/barchart.go)
[<img src="./_assets/gauge.png" alt="gauge" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/gauge.go)
[<img src="./_assets/linechart.png" alt="linechart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/linechart.go)
[<img src="./_assets/list.png" alt="list" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/list.go)
[<img src="./_assets/paragraph.png" alt="paragraph" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/paragraph.go)
[<img src="./_assets/sparkline.png" alt="sparkline" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/sparkline.go)
[<img src="./_assets/stacked_barchart.png" alt="stacked_barchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/stacked_barchart.go)
[<img src="./_assets/table.png" alt="table" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/table.go)
2015-02-08 17:00:00 +00:00
2018-11-29 03:15:29 +00:00
### Examples
2019-01-24 04:12:10 +00:00
Examples can be found in [\_examples](./_examples). Run an example with `go run _examples/{example}.go` or run all of them consecutively with `make run-examples`.
2018-11-29 03:15:29 +00:00
2019-01-24 04:12:10 +00:00
### Documentation
2018-11-29 03:15:29 +00:00
2019-01-24 04:12:10 +00:00
- [wiki](https://github.com/gizak/termui/wiki)
2015-02-08 17:00:00 +00:00
2018-11-29 03:15:29 +00:00
## Uses
2015-02-08 17:00:00 +00:00
2019-01-24 04:12:10 +00:00
- [cjbassi/gotop](https://github.com/cjbassi/gotop)
2018-11-29 03:15:29 +00:00
- [go-ethereum/monitorcmd](https://github.com/ethereum/go-ethereum/blob/96116758d22ddbff4dbef2050d6b63a7b74502d8/cmd/geth/monitorcmd.go)
2018-11-29 03:15:29 +00:00
## Related Works
2018-11-29 03:15:29 +00:00
- [blessed-contrib](https://github.com/yaronn/blessed-contrib)
- [tui-rs](https://github.com/fdehau/tui-rs)
- [gocui](https://github.com/jroimartin/gocui)
2015-10-27 19:24:29 +00:00
2015-02-08 17:00:00 +00:00
## License
2018-09-06 23:55:27 +00:00
2019-01-24 04:12:10 +00:00
[MIT](http://opensource.org/licenses/MIT)