2019-06-21 14:29:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-06-26 19:10:17 +00:00
|
|
|
"log"
|
|
|
|
|
2019-06-21 14:29:23 +00: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 22:18:34 +00:00
|
|
|
func (vc *View) CursorUp(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return MoveCursor(-1, g, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vc *View) CursorDown(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return MoveCursor(1, g, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func MoveCursor(mod int, g *gocui.Gui, v *gocui.View) error {
|
|
|
|
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 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
|
|
|
}
|