summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers/screen_mode_actions.go
blob: 1db27f2e25db0c0515816928b440f1f707ad6499 (plain)
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
package controllers

import (
	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

type ScreenModeActions struct {
	c *ControllerCommon
}

func (self *ScreenModeActions) Next() error {
	self.c.State().GetRepoState().SetScreenMode(
		nextIntInCycle(
			[]types.WindowMaximisation{types.SCREEN_NORMAL, types.SCREEN_HALF, types.SCREEN_FULL},
			self.c.State().GetRepoState().GetScreenMode(),
		),
	)

	return nil
}

func (self *ScreenModeActions) Prev() error {
	self.c.State().GetRepoState().SetScreenMode(
		prevIntInCycle(
			[]types.WindowMaximisation{types.SCREEN_NORMAL, types.SCREEN_HALF, types.SCREEN_FULL},
			self.c.State().GetRepoState().GetScreenMode(),
		),
	)

	return nil
}

func nextIntInCycle(sl []types.WindowMaximisation, current types.WindowMaximisation) types.WindowMaximisation {
	for i, val := range sl {
		if val == current {
			if i == len(sl)-1 {
				return sl[0]
			}
			return sl[i+1]
		}
	}
	return sl[0]
}

func prevIntInCycle(sl []types.WindowMaximisation, current types.WindowMaximisation) types.WindowMaximisation {
	for i, val := range sl {
		if val == current {
			if i > 0 {
				return sl[i-1]
			}
			return sl[len(sl)-1]
		}
	}
	return sl[len(sl)-1]
}