2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-16 00:12:44 +00:00
lntop/ui/views/cursor.go

68 lines
1.1 KiB
Go
Raw Normal View History

2019-04-10 11:32:11 +00:00
package views
import "github.com/jroimartin/gocui"
func cursorDown(v *gocui.View, speed int) error {
if v == nil {
return nil
}
cx, cy := v.Cursor()
err := v.SetCursor(cx, cy+speed)
if err != nil {
ox, oy := v.Origin()
err := v.SetOrigin(ox, oy+speed)
if err != nil {
return err
}
}
return nil
}
func cursorUp(v *gocui.View, speed int) error {
if v == nil {
return nil
}
ox, oy := v.Origin()
cx, cy := v.Cursor()
err := v.SetCursor(cx, cy-speed)
if err != nil && oy >= speed {
err := v.SetOrigin(ox, oy-speed)
if err != nil {
return err
}
}
return nil
}
func cursorRight(v *gocui.View, speed int) error {
if v == nil {
return nil
}
cx, cy := v.Cursor()
err := v.SetCursor(cx+speed, cy)
if err != nil {
ox, oy := v.Origin()
err := v.SetOrigin(ox+speed, oy)
if err != nil {
return err
}
}
return nil
}
func cursorLeft(v *gocui.View, speed int) error {
if v == nil {
return nil
}
ox, oy := v.Origin()
cx, cy := v.Cursor()
err := v.SetCursor(cx-speed, cy)
if err != nil && ox >= speed {
err := v.SetOrigin(ox-speed, oy)
if err != nil {
return err
}
}
return nil
}