summaryrefslogtreecommitdiffstats
path: root/pkg/utils/utils.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-02-25 08:32:46 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-02-25 08:41:53 +1100
commit91de559f15167ffd28ca274c96b9cfbf54f92fcd (patch)
tree6cc44c09ce40a15a9da066c2d568863c05dde90b /pkg/utils/utils.go
parent52b5a6410c33557f754c4a6cd3ce0c69220dc780 (diff)
add half and fullscreen modesv0.15
Diffstat (limited to 'pkg/utils/utils.go')
-rw-r--r--pkg/utils/utils.go26
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]
+}