_examples/delete: Add legend. Fix bug in nextView

This commit is contained in:
Roi Martin 2015-01-26 23:19:54 +01:00
parent d3c84c7bf4
commit 9404aacd27
1 changed files with 21 additions and 2 deletions

View File

@ -34,7 +34,7 @@ func main() {
if err := initKeybindings(g); err != nil { if err := initKeybindings(g); err != nil {
log.Panicln(err) log.Panicln(err)
} }
if err := newView(g); err != nil { if err := initViews(g); err != nil {
log.Panicln(err) log.Panicln(err)
} }
@ -97,6 +97,25 @@ func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrorQuit return gocui.ErrorQuit
} }
func initViews(g *gocui.Gui) error {
maxX, _ := g.Size()
v, err := g.SetView("legend", maxX-22, 0, maxX-1, 6)
if err != nil {
if err != gocui.ErrorUnkView {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
fmt.Fprintln(v, "Space: New View")
fmt.Fprintln(v, "Tab: Next View")
fmt.Fprintln(v, "← ↑ → ↓: Move View")
fmt.Fprintln(v, "^C: Exit")
}
if err := newView(g); err != nil {
log.Panicln(err)
}
return nil
}
func newView(g *gocui.Gui) error { func newView(g *gocui.Gui) error {
maxX, maxY := g.Size() maxX, maxY := g.Size()
name := fmt.Sprintf("v%v", idxView) name := fmt.Sprintf("v%v", idxView)
@ -155,7 +174,7 @@ func nextView(g *gocui.Gui, disableCurrent bool) error {
} }
nv.BgColor = gocui.ColorRed nv.BgColor = gocui.ColorRed
if disableCurrent { if disableCurrent && len(views) > 1 {
cv, err := g.View(views[curView]) cv, err := g.View(views[curView])
if err != nil { if err != nil {
return err return err