mirror of
https://github.com/jroimartin/gocui.git
synced 2025-05-08 19:29:28 +08:00
use standard errors when defining package level errors and wrap when percolating up
This commit is contained in:
parent
985c2f8d59
commit
5d41a21e5c
23
gui.go
23
gui.go
@ -5,6 +5,9 @@
|
|||||||
package gocui
|
package gocui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
standardErrors "errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
"github.com/jesseduffield/termbox-go"
|
"github.com/jesseduffield/termbox-go"
|
||||||
@ -12,10 +15,10 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrQuit is used to decide if the MainLoop finished successfully.
|
// ErrQuit is used to decide if the MainLoop finished successfully.
|
||||||
ErrQuit = errors.New("quit")
|
ErrQuit = standardErrors.New("quit")
|
||||||
|
|
||||||
// ErrUnknownView allows to assert if a View must be initialized.
|
// ErrUnknownView allows to assert if a View must be initialized.
|
||||||
ErrUnknownView = errors.New("unknown view")
|
ErrUnknownView = standardErrors.New("unknown view")
|
||||||
)
|
)
|
||||||
|
|
||||||
// OutputMode represents the terminal's output mode (8 or 256 colors).
|
// OutputMode represents the terminal's output mode (8 or 256 colors).
|
||||||
@ -163,7 +166,7 @@ func (g *Gui) SetView(name string, x0, y0, x1, y1 int, overlaps byte) (*View, er
|
|||||||
v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor
|
v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor
|
||||||
v.Overlaps = overlaps
|
v.Overlaps = overlaps
|
||||||
g.views = append(g.views, v)
|
g.views = append(g.views, v)
|
||||||
return v, ErrUnknownView
|
return v, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetViewOnTop sets the given view on top of the existing ones.
|
// SetViewOnTop sets the given view on top of the existing ones.
|
||||||
@ -175,7 +178,7 @@ func (g *Gui) SetViewOnTop(name string) (*View, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrUnknownView
|
return nil, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetViewOnBottom sets the given view on bottom of the existing ones.
|
// SetViewOnBottom sets the given view on bottom of the existing ones.
|
||||||
@ -187,7 +190,7 @@ func (g *Gui) SetViewOnBottom(name string) (*View, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrUnknownView
|
return nil, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Views returns all the views in the GUI.
|
// Views returns all the views in the GUI.
|
||||||
@ -203,7 +206,7 @@ func (g *Gui) View(name string) (*View, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrUnknownView
|
return nil, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewByPosition returns a pointer to a view matching the given position, or
|
// ViewByPosition returns a pointer to a view matching the given position, or
|
||||||
@ -216,7 +219,7 @@ func (g *Gui) ViewByPosition(x, y int) (*View, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrUnknownView
|
return nil, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewPosition returns the coordinates of the view with the given name, or
|
// ViewPosition returns the coordinates of the view with the given name, or
|
||||||
@ -227,7 +230,7 @@ func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error) {
|
|||||||
return v.x0, v.y0, v.x1, v.y1, nil
|
return v.x0, v.y0, v.x1, v.y1, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, 0, 0, 0, ErrUnknownView
|
return 0, 0, 0, 0, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteView deletes a view by name.
|
// DeleteView deletes a view by name.
|
||||||
@ -238,7 +241,7 @@ func (g *Gui) DeleteView(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ErrUnknownView
|
return errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentView gives the focus to a given view.
|
// SetCurrentView gives the focus to a given view.
|
||||||
@ -249,7 +252,7 @@ func (g *Gui) SetCurrentView(name string) (*View, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrUnknownView
|
return nil, errors.Wrap(ErrUnknownView, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentView returns the currently focused view, or nil if no view
|
// CurrentView returns the currently focused view, or nil if no view
|
||||||
|
Loading…
x
Reference in New Issue
Block a user