Skip to content

Commit

Permalink
Merge pull request #75 from bbrodriges/stderrors
Browse files Browse the repository at this point in the history
use Go 1.13 errors instead of go-errors/errors
  • Loading branch information
mjarkk authored Jan 14, 2021
2 parents c6cc4e8 + 6f7659f commit a0f5add
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 130 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions _examples/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"errors"
"fmt"
"log"

Expand Down Expand Up @@ -50,7 +51,7 @@ 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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v1 (editable)"
Expand All @@ -63,15 +64,15 @@ func layout(g *gocui.Gui) error {
}

if v, err := g.SetView("v2", maxX/2-1, 0, maxX-1, maxY/2-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v3"
Expand All @@ -80,7 +81,7 @@ func layout(g *gocui.Gui) error {
fmt.Fprint(v, "Press TAB to change current view")
}
if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v4 (editable)"
Expand Down Expand Up @@ -113,7 +114,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}
5 changes: 3 additions & 2 deletions _examples/bufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package main

import (
"errors"
"fmt"
"log"

Expand All @@ -29,7 +30,7 @@ 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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Editable = true
Expand Down Expand Up @@ -59,7 +60,7 @@ func main() {
log.Panicln(err)
}

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

Expand Down
4 changes: 2 additions & 2 deletions _examples/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
for i := 0; i <= 7; i++ {
Expand Down
4 changes: 2 additions & 2 deletions _examples/colors256.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func main() {
log.Panicln(err)
}

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

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

Expand Down
4 changes: 2 additions & 2 deletions _examples/colorstrue.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}
Expand All @@ -60,7 +60,7 @@ func layout(g *gocui.Gui) error {
}

if v, err := g.SetView("colors", 0, 0, cols-1, rows-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions _examples/custom_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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, gocui.RIGHT); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v1"
Expand All @@ -59,7 +59,7 @@ func layout(g *gocui.Gui) error {
}

if v, err := g.SetView("v2", maxX/2-1, 0, maxX-1, maxY/2-1, gocui.LEFT); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v2"
Expand All @@ -74,7 +74,7 @@ func layout(g *gocui.Gui) error {
fmt.Fprintln(v, "\033[32;2mSelected frame is highlighted with green color\033[0m")
}
if v, err := g.SetView("v3", 0, maxY/2, maxX/2-1, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v3"
Expand All @@ -87,7 +87,7 @@ func layout(g *gocui.Gui) error {
fmt.Fprintln(v, "It's not connected to any view.")
}
if v, err := g.SetView("v4", maxX/2, maxY/2, maxX-1, maxY-1, gocui.LEFT); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "v4"
Expand Down Expand Up @@ -135,7 +135,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}
8 changes: 4 additions & 4 deletions _examples/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
fmt.Fprintln(v, l)
Expand Down Expand Up @@ -160,7 +160,7 @@ 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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Highlight = true
Expand All @@ -173,7 +173,7 @@ func layout(g *gocui.Gui) error {
fmt.Fprint(v, "deleted\rItem 4\nItem 5")
}
if v, err := g.SetView("main", 30, -1, maxX, maxY, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
b, err := ioutil.ReadFile("Mark.Twain-Tom.Sawyer.txt")
Expand Down Expand Up @@ -205,7 +205,7 @@ func main() {
log.Panicln(err)
}

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

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}
Expand All @@ -49,7 +49,7 @@ func layout(g *gocui.Gui) error {
maxX, _ := g.Size()
v, err := g.SetView("help", maxX-25, 0, maxX-1, 9, 0)
if err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
Expand Down Expand Up @@ -135,7 +135,7 @@ func newView(g *gocui.Gui) error {
name := fmt.Sprintf("v%v", idxView)
v, err := g.SetView(name, maxX/2-5, maxY/2-5, maxX/2+5, maxY/2+5, 0)
if err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Wrap = true
Expand Down
6 changes: 3 additions & 3 deletions _examples/flow_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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, 0)
if err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
fmt.Fprint(v, w.body)
Expand All @@ -53,7 +53,7 @@ func flowLayout(g *gocui.Gui) error {
for _, v := range views {
w, h := v.Size()
_, err := g.SetView(v.Name(), x, 0, x+w+1, h+1, 0)
if err != nil && !gocui.IsUnknownView(err) {
if err != nil && !errors.Is(err, gocui.ErrUnknownView) {
return err
}
x += w + 2
Expand All @@ -80,7 +80,7 @@ func main() {
log.Panicln(err)
}

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

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

Expand All @@ -50,7 +50,7 @@ func main() {

func layout(g *gocui.Gui) error {
if v, err := g.SetView("ctr", 2, 2, 22, 2+NumGoroutines+1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Clear()
Expand Down
4 changes: 2 additions & 2 deletions _examples/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion _examples/keybinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
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, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions _examples/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (

func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if _, err := g.SetView("side", -1, -1, int(0.2*float32(maxX)), maxY-5, 0); err != nil && !gocui.IsUnknownView(err) {
if _, err := g.SetView("side", -1, -1, int(0.2*float32(maxX)), maxY-5, 0); err != nil && !errors.Is(err, gocui.ErrUnknownView) {
return err
}
if _, err := g.SetView("main", int(0.2*float32(maxX)), -1, maxX, maxY-5, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}

g.SetCurrentView("main")
}
if _, err := g.SetView("cmdline", -1, maxY-5, maxX, maxY, 0); err != nil && !gocui.IsUnknownView(err) {
if _, err := g.SetView("cmdline", -1, maxY-5, maxX, maxY, 0); err != nil && !errors.Is(err, gocui.ErrUnknownView) {
return err
}

Expand All @@ -46,7 +46,7 @@ func main() {
log.Panicln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Panicln(err)
}
}
6 changes: 3 additions & 3 deletions _examples/mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
log.Fatalln(err)
}

if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
log.Fatalln(err)
}
}
Expand All @@ -35,7 +35,7 @@ func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()

if v, err := g.SetView("help", maxX-23, 0, maxX-1, 3, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Title = "Keybindings"
Expand All @@ -44,7 +44,7 @@ func layout(g *gocui.Gui) error {
}

if v, err := g.SetView("input", 0, 0, maxX-24, maxY-1, 0); err != nil {
if !gocui.IsUnknownView(err) {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
if _, err := g.SetCurrentView("input"); err != nil {
Expand Down
Loading

0 comments on commit a0f5add

Please sign in to comment.