1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/snake"
)
type SnakeController struct {
baseController
*controllerCommon
getGame func() *snake.Game
}
var _ types.IController = &SnakeController{}
func NewSnakeController(
common *controllerCommon,
getGame func() *snake.Game,
) *SnakeController {
return &SnakeController{
baseController: baseController{},
controllerCommon: common,
getGame: getGame,
}
}
func (self *SnakeController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
Key: opts.GetKey(opts.Config.Universal.NextItem),
Handler: self.SetDirection(snake.Down),
},
{
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Handler: self.SetDirection(snake.Up),
},
{
Key: opts.GetKey(opts.Config.Universal.PrevBlock),
Handler: self.SetDirection(snake.Left),
},
{
Key: opts.GetKey(opts.Config.Universal.NextBlock),
Handler: self.SetDirection(snake.Right),
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Handler: self.Escape,
},
}
return bindings
}
func (self *SnakeController) Context() types.Context {
return self.contexts.Snake
}
func (self *SnakeController) SetDirection(direction snake.Direction) func() error {
return func() error {
self.getGame().SetDirection(direction)
return nil
}
}
func (self *SnakeController) Escape() error {
return self.c.PushContext(self.contexts.Submodules)
}
|