diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 08:32:46 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 08:45:30 +1100 |
commit | fdb543fa7de0879f9cc1b4d6bc189f1a7c271ebb (patch) | |
tree | 6cc44c09ce40a15a9da066c2d568863c05dde90b /pkg/utils | |
parent | 52b5a6410c33557f754c4a6cd3ce0c69220dc780 (diff) |
add half and fullscreen modesv0.15.1
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/utils.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1b69a9a5b..42529776f 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -322,3 +322,29 @@ func ModuloWithWrap(n, max int) int { return n } } + +// NextIntInCycle returns the next int in a slice, returning to the first index if we've reached the end +func NextIntInCycle(sl []int, current int) int { + for i, val := range sl { + if val == current { + if i == len(sl)-1 { + return sl[0] + } + return sl[i+1] + } + } + return sl[0] +} + +// PrevIntInCycle returns the prev int in a slice, returning to the first index if we've reached the end +func PrevIntInCycle(sl []int, current int) int { + 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] +} |