From c690c51bffa6309c09b8da9c2e3a47b146b74d14 Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Mon, 26 Jan 2015 23:23:46 +0100 Subject: [PATCH] _examples/delete: Move legend to layout --- _examples/delete.go | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/_examples/delete.go b/_examples/delete.go index e21487b..fa05119 100644 --- a/_examples/delete.go +++ b/_examples/delete.go @@ -29,12 +29,11 @@ func main() { } defer g.Close() - g.SetLayout(func(g *gocui.Gui) error { return nil }) - + g.SetLayout(layout) if err := initKeybindings(g); err != nil { log.Panicln(err) } - if err := initViews(g); err != nil { + if err := newView(g); err != nil { log.Panicln(err) } @@ -44,6 +43,22 @@ func main() { } } +func layout(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") + } + return nil +} + func initKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { return err @@ -97,25 +112,6 @@ 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)