Skip to content

Commit

Permalink
Update dynamic.go to add SetViewOnBottom
Browse files Browse the repository at this point in the history
  • Loading branch information
jroimartin committed Aug 15, 2017
1 parent a984617 commit c48e902
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions _examples/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {

func layout(g *gocui.Gui) error {
maxX, _ := g.Size()
v, err := g.SetView("help", maxX-25, 0, maxX-1, 8)
v, err := g.SetView("help", maxX-25, 0, maxX-1, 9)
if err != nil {
if err != gocui.ErrUnknownView {
return err
Expand All @@ -57,13 +57,17 @@ func layout(g *gocui.Gui) error {
fmt.Fprintln(v, "← ↑ → ↓: Move View")
fmt.Fprintln(v, "Backspace: Delete View")
fmt.Fprintln(v, "t: Set view on top")
fmt.Fprintln(v, "b: Set view on bottom")
fmt.Fprintln(v, "^C: Exit")
}
return nil
}

func initKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}); err != nil {
return err
}
if err := g.SetKeybinding("", gocui.KeySpace, gocui.ModNone,
Expand Down Expand Up @@ -108,16 +112,23 @@ func initKeybindings(g *gocui.Gui) error {
}); err != nil {
return err
}
if err := g.SetKeybinding("", 't', gocui.ModNone, ontop); err != nil {
if err := g.SetKeybinding("", 't', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
_, err := g.SetViewOnTop(views[curView])
return err
}); err != nil {
return err
}
if err := g.SetKeybinding("", 'b', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
_, err := g.SetViewOnBottom(views[curView])
return err
}); err != nil {
return err
}
return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

func newView(g *gocui.Gui) error {
maxX, maxY := g.Size()
name := fmt.Sprintf("v%v", idxView)
Expand Down Expand Up @@ -177,8 +188,3 @@ func moveView(g *gocui.Gui, v *gocui.View, dx, dy int) error {
}
return nil
}

func ontop(g *gocui.Gui, v *gocui.View) error {
_, err := g.SetViewOnTop(views[curView])
return err
}

0 comments on commit c48e902

Please sign in to comment.