2019-06-21 10:29:23 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-06-26 15:10:17 -04:00
|
|
|
"log"
|
|
|
|
|
2019-06-21 10:29:23 -04:00
|
|
|
"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 19:54:04 -04:00
|
|
|
func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return MoveCursor(-1, v)
|
2019-06-26 18:18:34 -04:00
|
|
|
}
|
|
|
|
|
2019-06-26 19:54:04 -04:00
|
|
|
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
|
2019-06-26 19:57:02 -04:00
|
|
|
peers := vc.State.(*PeersState).list
|
2019-06-26 19:54:04 -04:00
|
|
|
_, cy := v.Cursor()
|
|
|
|
// Don't go beyond available list of peers
|
|
|
|
if cy+1 >= len(peers) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return MoveCursor(1, v)
|
2019-06-26 18:18:34 -04:00
|
|
|
}
|
|
|
|
|
2019-06-26 19:54:04 -04:00
|
|
|
func MoveCursor(mod int, v *gocui.View) error {
|
2019-06-26 18:18:34 -04:00
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
_, my := v.Size()
|
|
|
|
cx, cy := v.Cursor()
|
|
|
|
log.Printf("my: %d, cx: %d, cy: %d", my, cx, cy)
|
|
|
|
if cy+mod < 0 || cy+mod == my {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := v.SetCursor(cx, cy+mod); err != nil {
|
|
|
|
if mod == -1 {
|
2019-06-21 14:53:50 -04:00
|
|
|
return nil
|
|
|
|
}
|
2019-06-26 18:18:34 -04:00
|
|
|
ox, oy := v.Origin()
|
|
|
|
if err := v.SetOrigin(ox, oy+mod); err != nil {
|
|
|
|
return err
|
2019-06-21 10:29:23 -04:00
|
|
|
}
|
|
|
|
}
|
2019-06-26 18:18:34 -04:00
|
|
|
return nil
|
2019-06-21 10:29:23 -04:00
|
|
|
}
|