Skip to content

Commit

Permalink
Merge jesseduffields master (#8)
Browse files Browse the repository at this point in the history
Merge jesseduffields master

Co-authored-by: Kobe Lipkens <[email protected]>
Co-authored-by: Jesse Duffield <[email protected]>
Co-authored-by: null <[email protected]>
  • Loading branch information
4 people authored Apr 29, 2019
2 parents 23d04c9 + c62d980 commit f4d7a4b
Show file tree
Hide file tree
Showing 28 changed files with 606 additions and 275 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Or visit [godoc.org](https://godoc.org/github.com/awesome-gocui/gocui) to read i
online.

## Example
See the [_example](./_example/) folder for more examples

```go
package main
Expand All @@ -60,18 +61,21 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}

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 {
if !gocui.IsUnknownView(err) {
return err
}
fmt.Fprintln(v, "Hello world!")
if _, err := g.SetCurrentView("hello"); err != nil {
return err
}
}
return nil
}
Expand Down
20 changes: 10 additions & 10 deletions _examples/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func nextView(g *gocui.Gui, v *gocui.View) error {

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("v1", 0, 0, maxX/2-1, maxY/2-1); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("v1", 0, 0, maxX/2-1, maxY/2-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v1 (editable)"
Expand All @@ -62,25 +62,25 @@ func layout(g *gocui.Gui) error {
}
}

if v, err := g.SetView("v2", maxX/2-1, 0, maxX-1, maxY/2-1); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("v2", maxX/2-1, 0, maxX-1, maxY/2-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v2"
v.Wrap = true
v.Autoscroll = true
}
if v, err := g.SetView("v3", 0, maxY/2-1, maxX/2-1, maxY-1); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("v3", 0, maxY/2-1, maxX/2-1, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v3"
v.Wrap = true
v.Autoscroll = true
fmt.Fprint(v, "Press TAB to change current view")
}
if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Title = "v4 (editable)"
Expand All @@ -94,7 +94,7 @@ func quit(g *gocui.Gui, v *gocui.View) error {
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -113,7 +113,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}
8 changes: 4 additions & 4 deletions _examples/bufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func overwrite(g *gocui.Gui, v *gocui.View) error {

func layout(g *gocui.Gui) error {
_, maxY := g.Size()
if v, err := g.SetView("main", 0, 0, 20, maxY-1); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("main", 0, 0, 20, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Editable = true
Expand All @@ -42,7 +42,7 @@ func layout(g *gocui.Gui) error {
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -59,7 +59,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}

Expand Down
11 changes: 7 additions & 4 deletions _examples/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -24,22 +24,25 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("colors", maxX/2-7, maxY/2-12, maxX/2+7, maxY/2+13); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("colors", maxX/2-7, maxY/2-12, maxX/2+7, maxY/2+13, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
for i := 0; i <= 7; i++ {
for _, j := range []int{1, 4, 7} {
fmt.Fprintf(v, "Hello \033[3%d;%dmcolors!\033[0m\n", i, j)
}
}
if _, err := g.SetCurrentView("colors"); err != nil {
return err
}
}
return nil
}
Expand Down
11 changes: 7 additions & 4 deletions _examples/colors256.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func main() {
g, err := gocui.NewGui(gocui.Output256)
g, err := gocui.NewGui(gocui.Output256, true)

if err != nil {
log.Panicln(err)
Expand All @@ -25,15 +25,15 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("colors", -1, -1, maxX, maxY); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("colors", -1, -1, maxX, maxY, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}

Expand Down Expand Up @@ -65,6 +65,9 @@ func layout(g *gocui.Gui) error {
ctr++
}
}
if _, err := g.SetCurrentView("colors"); err != nil {
return err
}
}
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions _examples/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func getLine(g *gocui.Gui, v *gocui.View) error {
}

maxX, maxY := g.Size()
if v, err := g.SetView("msg", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("msg", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
fmt.Fprintln(v, l)
Expand Down Expand Up @@ -159,8 +159,8 @@ func saveVisualMain(g *gocui.Gui, v *gocui.View) error {

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("side", -1, -1, 30, maxY); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("side", -1, -1, 30, maxY, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
v.Highlight = true
Expand All @@ -172,8 +172,8 @@ func layout(g *gocui.Gui) error {
fmt.Fprint(v, "\rWill be")
fmt.Fprint(v, "deleted\rItem 4\nItem 5")
}
if v, err := g.SetView("main", 30, -1, maxX, maxY); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("main", 30, -1, maxX, maxY, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
b, err := ioutil.ReadFile("Mark.Twain-Tom.Sawyer.txt")
Expand All @@ -191,7 +191,7 @@ func layout(g *gocui.Gui) error {
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -205,7 +205,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}
14 changes: 7 additions & 7 deletions _examples/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
)

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -39,16 +39,16 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}

func layout(g *gocui.Gui) error {
maxX, _ := g.Size()
v, err := g.SetView("help", maxX-25, 0, maxX-1, 9)
v, err := g.SetView("help", maxX-25, 0, maxX-1, 9, 0)
if err != nil {
if err != gocui.ErrUnknownView {
if !gocui.IsUnknownView(err) {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
Expand Down Expand Up @@ -132,9 +132,9 @@ func initKeybindings(g *gocui.Gui) error {
func newView(g *gocui.Gui) error {
maxX, maxY := g.Size()
name := fmt.Sprintf("v%v", idxView)
v, err := g.SetView(name, maxX/2-5, maxY/2-5, maxX/2+5, maxY/2+5)
v, err := g.SetView(name, maxX/2-5, maxY/2-5, maxX/2+5, maxY/2+5, 0)
if err != nil {
if err != gocui.ErrUnknownView {
if !gocui.IsUnknownView(err) {
return err
}
v.Wrap = true
Expand Down Expand Up @@ -183,7 +183,7 @@ func moveView(g *gocui.Gui, v *gocui.View, dx, dy int) error {
if err != nil {
return err
}
if _, err := g.SetView(name, x0+dx, y0+dy, x1+dx, y1+dy); err != nil {
if _, err := g.SetView(name, x0+dx, y0+dy, x1+dx, y1+dy, 0); err != nil {
return err
}
return nil
Expand Down
15 changes: 9 additions & 6 deletions _examples/flow_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ func NewLabel(name string, body string) *Label {
}

func (w *Label) Layout(g *gocui.Gui) error {
v, err := g.SetView(w.name, 0, 0, w.w, w.h)
v, err := g.SetView(w.name, 0, 0, w.w, w.h, 0)
if err != nil {
if err != gocui.ErrUnknownView {
if !gocui.IsUnknownView(err) {
return err
}
fmt.Fprint(v, w.body)
if _, err := g.SetCurrentView(w.name); err != nil {
return err
}
}
return nil
}
Expand All @@ -49,8 +52,8 @@ func flowLayout(g *gocui.Gui) error {
x := 0
for _, v := range views {
w, h := v.Size()
_, err := g.SetView(v.Name(), x, 0, x+w+1, h+1)
if err != nil && err != gocui.ErrUnknownView {
_, err := g.SetView(v.Name(), x, 0, x+w+1, h+1, 0)
if err != nil && !gocui.IsUnknownView(err) {
return err
}
x += w + 2
Expand All @@ -59,7 +62,7 @@ func flowLayout(g *gocui.Gui) error {
}

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -77,7 +80,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}
}
Expand Down
11 changes: 7 additions & 4 deletions _examples/goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
)

func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
log.Panicln(err)
}
Expand All @@ -41,19 +41,22 @@ func main() {
go counter(g)
}

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
log.Panicln(err)
}

wg.Wait()
}

func layout(g *gocui.Gui) error {
if v, err := g.SetView("ctr", 2, 2, 12, 4); err != nil {
if err != gocui.ErrUnknownView {
if v, err := g.SetView("ctr", 2, 2, 12, 4, 0); err != nil {
if !gocui.IsUnknownView(err) {
return err
}
fmt.Fprintln(v, "0")
if _, err := g.SetCurrentView("ctr"); err != nil {
return err
}
}
return nil
}
Expand Down
Loading

0 comments on commit f4d7a4b

Please sign in to comment.