mirror of
https://github.com/status-im/status-go-monitor.git
synced 2025-01-28 03:54:44 +00:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/jroimartin/gocui"
|
|
)
|
|
|
|
type Binding struct {
|
|
Key interface{} // so both gocui.Key and rune work
|
|
Mod gocui.Modifier
|
|
Handler func(g *gocui.Gui, v *gocui.View) error
|
|
}
|
|
|
|
func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error {
|
|
return MoveCursor(-1, vc, g, v)
|
|
}
|
|
|
|
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
|
|
return MoveCursor(1, vc, g, v)
|
|
}
|
|
|
|
func MoveCursor(mod int, vc *ViewController, g *gocui.Gui, v *gocui.View) error {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
cx, cy := v.Cursor()
|
|
// get peers
|
|
ps := vc.State.GetState()
|
|
peers := ps.Peers
|
|
// Don't go beyond available list of peers
|
|
if cy+mod >= len(peers) || cy+mod < 0 {
|
|
return nil
|
|
}
|
|
// update currently selected peer in the list
|
|
vc.State.SetCurrent(cy + mod)
|
|
|
|
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
|
|
}
|
|
|
|
func (vc *ViewController) HandleDelete(g *gocui.Gui, v *gocui.View) error {
|
|
currentPeer := vc.State.GetCurrent()
|
|
err := vc.State.Remove(currentPeer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|