diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-31 23:55:06 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-02 11:00:15 +1100 |
commit | 7d62f103e4a1b39b7e8fbd0e1f39815c525cd588 (patch) | |
tree | 83e331beeee07d066c76580e044234f18063a0a7 /pkg/gui/global_handlers.go | |
parent | 9e85d37fb949bbc83f28cb079f2ac4b45ae895ce (diff) |
big refactor to give our enums actual types
Diffstat (limited to 'pkg/gui/global_handlers.go')
-rw-r--r-- | pkg/gui/global_handlers.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index d0c357df0..2db37e5d4 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -22,14 +22,40 @@ func (gui *Gui) rerenderViewsWithScreenModeDependentContent() error { return nil } +// TODO: GENERICS +func nextIntInCycle(sl []WindowMaximisation, current WindowMaximisation) WindowMaximisation { + for i, val := range sl { + if val == current { + if i == len(sl)-1 { + return sl[0] + } + return sl[i+1] + } + } + return sl[0] +} + +// TODO: GENERICS +func prevIntInCycle(sl []WindowMaximisation, current WindowMaximisation) 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] +} + func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { - gui.State.ScreenMode = utils.NextIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.State.ScreenMode = nextIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) return gui.rerenderViewsWithScreenModeDependentContent() } func (gui *Gui) prevScreenMode(g *gocui.Gui, v *gocui.View) error { - gui.State.ScreenMode = utils.PrevIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.State.ScreenMode = prevIntInCycle([]WindowMaximisation{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) return gui.rerenderViewsWithScreenModeDependentContent() } @@ -179,7 +205,7 @@ func (gui *Gui) fetch(canPromptForCredentials bool) (err error) { _ = gui.createErrorPanel(gui.Tr.PassUnameWrong) } - _ = gui.refreshSidePanels(refreshOptions{scope: []int{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC}) + _ = gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC}) return err } |