2019-06-21 14:29:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Binding struct {
|
|
|
|
Key gocui.Key
|
|
|
|
Mod gocui.Modifier
|
|
|
|
Handler func(g *gocui.Gui, v *gocui.View) error
|
|
|
|
}
|
|
|
|
|
2019-06-26 23:54:04 +00:00
|
|
|
func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error {
|
2019-06-27 02:31:40 +00:00
|
|
|
return MoveCursor(-1, vc, g, v)
|
2019-06-26 22:18:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 23:54:04 +00:00
|
|
|
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
|
2019-06-27 02:31:40 +00:00
|
|
|
return MoveCursor(1, vc, g, v)
|
2019-06-26 22:18:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 02:31:40 +00:00
|
|
|
func MoveCursor(mod int, vc *ViewController, g *gocui.Gui, v *gocui.View) error {
|
2019-06-26 22:18:34 +00:00
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cx, cy := v.Cursor()
|
2019-06-27 02:31:40 +00:00
|
|
|
// get peers
|
|
|
|
ps := vc.State.(*PeersState)
|
|
|
|
peers := ps.list
|
|
|
|
// Don't go beyond available list of peers
|
|
|
|
if cy+mod >= len(peers) || cy+mod < 0 {
|
2019-06-26 22:18:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-06-27 02:31:40 +00:00
|
|
|
// update currently selected peer in the list
|
|
|
|
ps.selected = &peers[cy+mod]
|
|
|
|
writePeerDetails(g, ps.selected)
|
2019-06-26 22:18:34 +00:00
|
|
|
if err := v.SetCursor(cx, cy+mod); err != nil {
|
|
|
|
if mod == -1 {
|
2019-06-21 18:53:50 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-06-26 22:18:34 +00:00
|
|
|
ox, oy := v.Origin()
|
|
|
|
if err := v.SetOrigin(ox, oy+mod); err != nil {
|
|
|
|
return err
|
2019-06-21 14:29:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 22:18:34 +00:00
|
|
|
return nil
|
2019-06-21 14:29:23 +00:00
|
|
|
}
|