From 9404aacd27ffc3bead2ec5c9b9c78fab237809d3 Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Mon, 26 Jan 2015 23:19:54 +0100 Subject: [PATCH] _examples/delete: Add legend. Fix bug in nextView --- _examples/delete.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/_examples/delete.go b/_examples/delete.go index 699f0e8..e21487b 100644 --- a/_examples/delete.go +++ b/_examples/delete.go @@ -34,7 +34,7 @@ func main() { if err := initKeybindings(g); err != nil { log.Panicln(err) } - if err := newView(g); err != nil { + if err := initViews(g); err != nil { log.Panicln(err) } @@ -97,6 +97,25 @@ func quit(g *gocui.Gui, v *gocui.View) error { 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 { maxX, maxY := g.Size() name := fmt.Sprintf("v%v", idxView) @@ -155,7 +174,7 @@ func nextView(g *gocui.Gui, disableCurrent bool) error { } nv.BgColor = gocui.ColorRed - if disableCurrent { + if disableCurrent && len(views) > 1 { cv, err := g.View(views[curView]) if err != nil { return err