diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 15:44:17 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 15:44:17 +0300 |
| commit | 6b91e76cfdd409e494fc2555af48037bbe286800 (patch) | |
| tree | 2a0975d12900b78a8b4b550f43c73261b2a000ba /go-src | |
| parent | 8c758581a466f640201d044bf18a95882e1c86c3 (diff) | |
| download | ctfc-6b91e76cfdd409e494fc2555af48037bbe286800.tar ctfc-6b91e76cfdd409e494fc2555af48037bbe286800.tar.gz ctfc-6b91e76cfdd409e494fc2555af48037bbe286800.zip | |
Moved ctfcMath functionality to utils
Diffstat (limited to 'go-src')
| -rw-r--r-- | go-src/ctfcMath/ctfcMath.go | 14 | ||||
| -rw-r--r-- | go-src/utils/utils.go | 12 | ||||
| -rw-r--r-- | go-src/windows.go | 3 | ||||
| -rw-r--r-- | go-src/windowsHelpers.go | 6 |
4 files changed, 16 insertions, 19 deletions
diff --git a/go-src/ctfcMath/ctfcMath.go b/go-src/ctfcMath/ctfcMath.go deleted file mode 100644 index 5dfc613..0000000 --- a/go-src/ctfcMath/ctfcMath.go +++ /dev/null @@ -1,14 +0,0 @@ -package ctfcmath - -import "math" - -func MaxInt(x int, y int) int { - if x > y { - return x - } - return y -} - -func CeilDivInt(x int, y int) int { - return int(math.Ceil(float64(x) / float64(y))) -} diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go index d241da6..a6aa08f 100644 --- a/go-src/utils/utils.go +++ b/go-src/utils/utils.go @@ -1,6 +1,7 @@ package utils import ( + "math" "os" ) @@ -38,6 +39,17 @@ func StrShortenRight(s *string, amount int) { *s = (*s)[:len(*s)-amount] } +func MaxInt(x int, y int) int { + if x > y { + return x + } + return y +} + +func CeilDivInt(x int, y int) int { + return int(math.Ceil(float64(x) / float64(y))) +} + // Special thanks to icza, over on https://stackoverflow.com/a/59375088 for the If constuction type If bool diff --git a/go-src/windows.go b/go-src/windows.go index afc4e77..70da48c 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -5,7 +5,6 @@ import ( "strings" "gitlab.com/Syndamia/ctfc/go-src/csi" - ctfcmath "gitlab.com/Syndamia/ctfc/go-src/ctfcMath" "gitlab.com/Syndamia/ctfc/go-src/ui" "gitlab.com/Syndamia/ctfc/go-src/utils" ) @@ -115,7 +114,7 @@ func chatsWindow(values ...string) { // If user input is number, navigate to chat of given number, else show error chatI, err := strconv.Atoi(input) if chatI >= 0 && chatI <= len(allChats) && err == nil { - defer chatWindow(strings.Split(allChats[ctfcmath.MaxInt(len(allChats)-pageSize*len(values[0]), 0)+chatI-1], " : ")[0]) + defer chatWindow(strings.Split(allChats[utils.MaxInt(len(allChats)-pageSize*len(values[0]), 0)+chatI-1], " : ")[0]) } else { switch input { case ">": diff --git a/go-src/windowsHelpers.go b/go-src/windowsHelpers.go index c94616c..beef465 100644 --- a/go-src/windowsHelpers.go +++ b/go-src/windowsHelpers.go @@ -5,8 +5,8 @@ import ( "time" "gitlab.com/Syndamia/ctfc/go-src/csi" - ctfcmath "gitlab.com/Syndamia/ctfc/go-src/ctfcMath" "gitlab.com/Syndamia/ctfc/go-src/ui" + "gitlab.com/Syndamia/ctfc/go-src/utils" ) /* Pagination */ @@ -14,11 +14,11 @@ import ( const pageSize = 15 func totalPages(messageAmount int) int { - return ctfcmath.CeilDivInt(messageAmount, pageSize) + return utils.CeilDivInt(messageAmount, pageSize) } func paginate(page int, messages ...string) []string { - return messages[ctfcmath.MaxInt(len(messages)-pageSize*page, 0) : len(messages)-pageSize*(page-1)] + return messages[utils.MaxInt(len(messages)-pageSize*page, 0) : len(messages)-pageSize*(page-1)] } // Must be run in a routine ( go routinePaginatedSubwindow(...) ) |
