Skip to content

Commit

Permalink
The great rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Jan 24, 2019
1 parent b3075f7 commit 0a017ee
Show file tree
Hide file tree
Showing 95 changed files with 2,598 additions and 4,946 deletions.
26 changes: 1 addition & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
.DS_Store
/vendor
.vscode/
.mypy_cache/
.idea
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
Feel free to search/open an issue if something is missing or confusing from the changelog, since many things have been in flux.

## TODO

- moved widgets to `github.com/gizak/termui/widgets`
- rewrote widgets (check examples and code)
- rewrote grid
- grids are instantiated locally instead of through `termui.Body`
- grids can be nested
- changed grid layout mechanism
- columns and rows can be arbitrarily nested
- column and row size is now specified as a ratio of the available space
- `Cell`s now contain a `Style` which holds a `Fg`, `Bg`, and `Modifier`
- Change `Bufferer` interface to `Drawable`
- Add `GetRect` and `SetRect` methods to control widget sizing
- Change `Buffer` method to `Draw`
- `Draw` takes a `Buffer` and draws to it instead of returning a new `Buffer`
- Refactored `Theme`
- `Theme` is now a large struct which holds the default `Styles` of everything
- Combined `TermWidth` and `TermHeight` functions into `TerminalDimensions`
- Added `Canvas` which allows for drawing braille lines to a `Buffer`
- Refactored `Block`
- Refactored `Buffer` methods
- Set `termbox-go` backend to 256 colors by default
- Decremented color numbers by 1 to match xterm colors
- Changed text parsing
- style items changed from `fg-color` to `fg:color`
- added mod item like `mod:reverse`

## 18/11/29

- Move Tabpane from termui/extra to termui and rename it to TabPane
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: run-examples
run-examples:
@for file in _examples/*.go; do \
go run $$file; \
done;
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# termui

[![Build Status](https://travis-ci.org/gizak/termui.svg?branch=master)](https://travis-ci.org/gizak/termui) [![Doc Status](https://godoc.org/github.com/gizak/termui?status.png)](https://godoc.org/github.com/gizak/termui)
<img src="./_assets/dashboard1.gif" alt="demo cast under osx 10.10; Terminal.app; Menlo Regular 12pt.)" width="100%">

<img src="./_examples/dashboard.gif" alt="demo cast under osx 10.10; Terminal.app; Menlo Regular 12pt.)" width="100%">

`termui` is a cross-platform, easy-to-compile, and fully-customizable terminal dashboard 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.

**termui is currently undergoing some API changes so make sure to check the changelog when upgrading**
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.

## Installation

Expand All @@ -16,25 +12,33 @@ Installing from the master branch is recommended:
go get -u github.com/gizak/termui@master
```

**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.

## Usage

### Hello World

```go
package main

import ui "github.com/gizak/termui"
import (
"log"

ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)

func main() {
err := ui.Init()
if err != nil {
panic(err)
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()

p := ui.NewParagraph("Hello World!")
p.Width = 25
p.Height = 5
p := widgets.NewParagraph()
p.Text = "Hello World!"
p.SetRect(0, 0, 25, 5)

ui.Render(p)

for e := range ui.PollEvents() {
Expand All @@ -49,26 +53,26 @@ func main() {

Click image to see the corresponding demo codes.

[<img src="./_examples/barchart.png" alt="barchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/barchart.go)
[<img src="./_examples/gauge.png" alt="gauge" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/gauge.go)
[<img src="./_examples/linechart.png" alt="linechart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/linechart.go)
[<img src="./_examples/list.png" alt="list" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/list.go)
[<img src="./_examples/paragraph.png" alt="paragraph" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/paragraph.go)
[<img src="./_examples/sparklines.png" alt="sparklines" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/sparklines.go)
[<img src="./_examples/stackedbarchart.png" alt="stackedbarchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/stackedbarchart.go)
[<img src="./_examples/table.png" alt="table" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_examples/table.go)
[<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)

### Examples

Examples can be found in [\_examples](./_examples). Run with `go run _examples/...` or run all of them consecutively with `./scripts/run_examples.py`.
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`.

## Documentation
### Documentation

- [godoc](https://godoc.org/github.com/gizak/termui) for code documentation
- [wiki](https://github.com/gizak/termui/wiki) for general information
- [wiki](https://github.com/gizak/termui/wiki)

## Uses

- [cjbassi/gotop](https://github.com/cjbassi/gotop)
- [go-ethereum/monitorcmd](https://github.com/ethereum/go-ethereum/blob/96116758d22ddbff4dbef2050d6b63a7b74502d8/cmd/geth/monitorcmd.go)

## Related Works
Expand All @@ -79,4 +83,4 @@ Examples can be found in [\_examples](./_examples). Run with `go run _examples/.

## License

This library is under the [MIT License](http://opensource.org/licenses/MIT)
[MIT](http://opensource.org/licenses/MIT)
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
30 changes: 17 additions & 13 deletions _examples/barchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@

package main

import ui "github.com/gizak/termui"
import (
"log"

ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)

func main() {
err := ui.Init()
if err != nil {
panic(err)
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()

bc := ui.NewBarChart()
bc.Data = []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
bc.BorderLabel = "Bar Chart"
bc.Width = 26
bc.Height = 10
bc.TextColor = ui.ColorGreen
bc.BarColor = ui.ColorRed
bc.NumColor = ui.ColorYellow
bc := widgets.NewBarChart()
bc.Data = []float64{3, 2, 5, 3, 9, 3}
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
bc.Title = "Bar Chart"
bc.SetRect(5, 5, 100, 25)
bc.BarWidth = 5
bc.BarColors = []ui.Color{ui.ColorRed, ui.ColorGreen}
bc.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorBlue)}
bc.NumStyles = []ui.Style{ui.NewStyle(ui.ColorYellow)}

ui.Render(bc)

Expand Down
30 changes: 30 additions & 0 deletions _examples/canvas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// +build ignore

package main

import (
"image"
"log"

ui "github.com/gizak/termui"
)

func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()

c := ui.NewCanvas()
c.SetRect(0, 0, 50, 50)
c.Line(image.Pt(0, 0), image.Pt(80, 50), ui.ColorClear)
c.Line(image.Pt(0, 5), image.Pt(3, 10), ui.ColorClear)

ui.Render(c)

for e := range ui.PollEvents() {
if e.Type == ui.KeyboardEvent {
break
}
}
}
Loading

0 comments on commit 0a017ee

Please sign in to comment.