move all ViewController methods to view.go
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
923ae10e4a
commit
742a6766b4
32
keys.go
32
keys.go
|
@ -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
28
view.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue