move all ViewController methods to view.go

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-28 16:25:56 -04:00 committed by Jakub
parent 923ae10e4a
commit 742a6766b4
3 changed files with 28 additions and 33 deletions

View File

@ -1,4 +1,3 @@
default: status-monitor
run:

32
keys.go
View File

@ -1,32 +0,0 @@
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 {
// TODO propper error handling?
vc.State.SetCurrent(vc.State.GetState().Current - 1)
return nil
}
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
// TODO propper error handling?
vc.State.SetCurrent(vc.State.GetState().Current + 1)
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
}

28
view.go
View File

@ -7,6 +7,13 @@ import (
"github.com/jroimartin/gocui"
)
// Struct for more succint definitions of key bindings
type Binding struct {
Key interface{} // so both gocui.Key and rune work
Mod gocui.Modifier
Handler func(g *gocui.Gui, v *gocui.View) error
}
// Default Gocui views arent granular enough
// so I'm adding a custom one to have more control.
type ViewController struct {
@ -84,3 +91,24 @@ func (v *ViewController) SetKeybindings(g *gocui.Gui) error {
}
return nil
}
func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error {
// TODO propper error handling?
vc.State.SetCurrent(vc.State.GetState().Current - 1)
return nil
}
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
// TODO propper error handling?
vc.State.SetCurrent(vc.State.GetState().Current + 1)
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
}