mirror of
https://github.com/status-im/status-go-monitor.git
synced 2025-01-26 11:09:16 +00:00
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
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
|
|
}
|
|
|
|
var bindings = [...]Binding{
|
|
Binding{gocui.KeyCtrlC, gocui.ModNone, quit},
|
|
Binding{gocui.KeyArrowUp, gocui.ModNone, HandlerCursorDispenser(-1)},
|
|
Binding{gocui.KeyArrowDown, gocui.ModNone, HandlerCursorDispenser(1)},
|
|
}
|
|
|
|
func keybindings(g *gocui.Gui) error {
|
|
for _, b := range bindings {
|
|
if err := g.SetKeybinding("", b.Key, b.Mod, b.Handler); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func HandlerCursorDispenser(mod int) func(g *gocui.Gui, v *gocui.View) error {
|
|
return func(g *gocui.Gui, v *gocui.View) error {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
mx, _ := v.Size()
|
|
cx, cy := v.Cursor()
|
|
if cy == 0 || cx == mx {
|
|
return nil
|
|
}
|
|
if err := v.SetCursor(cx, cy+mod); err != nil {
|
|
if mod == -1 {
|
|
return nil
|
|
}
|
|
ox, oy := v.Origin()
|
|
if err := v.SetOrigin(ox, oy+mod); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|