mirror of https://github.com/jroimartin/gocui.git
_examples/delete: Move legend to layout
This commit is contained in:
parent
9404aacd27
commit
c690c51bff
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue