summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-16 16:20:05 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-21 22:07:14 +1100
commit92e43d9e7776cd2e1796bf280756c6ffa7c8dbe2 (patch)
treeac3b7ee152e6b8cde6268d8c329334041cfe0d97 /pkg/utils
parent325408d0e3db8e1b7d0b6915986f1a684ee8b257 (diff)
allow changing tabs with [ and ]
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/utils.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index bf69fd30e..26d1b9021 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -299,3 +299,14 @@ func DifferenceInt(a, b []int) []int {
}
return result
}
+
+// used to keep a number n between 0 and max, allowing for wraparounds
+func ModuloWithWrap(n, max int) int {
+ if n >= max {
+ return n % max
+ } else if n < 0 {
+ return max + n
+ } else {
+ return n
+ }
+}