From 6b91e76cfdd409e494fc2555af48037bbe286800 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 22 Jul 2021 15:44:17 +0300 Subject: Moved ctfcMath functionality to utils --- go-src/ctfcMath/ctfcMath.go | 14 -------------- go-src/utils/utils.go | 12 ++++++++++++ go-src/windows.go | 3 +-- go-src/windowsHelpers.go | 6 +++--- 4 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 go-src/ctfcMath/ctfcMath.go 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(...) ) -- cgit v1.2.3