From 8c758581a466f640201d044bf18a95882e1c86c3 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 22 Jul 2021 15:41:06 +0300 Subject: Implemented chats page number selection and fixed initPaginatiedValues function --- go-src/windows.go | 27 ++++++++++++++++++++++----- go-src/windowsHelpers.go | 6 +++--- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'go-src') diff --git a/go-src/windows.go b/go-src/windows.go index 3d9c919..afc4e77 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -5,6 +5,7 @@ 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" ) @@ -81,7 +82,7 @@ func registerWindow(values ...string) { func chatsWindow(values ...string) { csi.ClearScreen() - initPaginatedValues(0, values) + initPaginatedValues(0, &values) ui.NormalBox(true, directMessagesNavTitle, accountNavTitle, logoutNavTitle) @@ -112,10 +113,26 @@ func chatsWindow(values ...string) { if handled == nil { // If user input is number, navigate to chat of given number, else show error - if chatI, err := strconv.Atoi(input); chatI >= 0 && chatI <= len(allChats) && err == nil { - defer chatWindow(strings.Split(allChats[chatI-1], " : ")[0]) + 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]) } else { - defer showError(invalidCommand, chatsWindow) + switch input { + case ">": + // If possible, increment to the next page (adds a dot to the end of the string) + if len(values[0]) < totalPages(len(allChats)) { + values[0] += "." + } + case "<": + // If possible, decrement to the previous page (removes a dot from the string) + if len(values[0]) > 1 { + utils.StrShortenRight(&values[0], 1) + } + default: + defer showError(invalidCommand, chatsWindow) + } + + defer chatsWindow(values...) } } else { defer handled() @@ -148,7 +165,7 @@ func chatWindow(values ...string) { // We determine page number by length of a string // This method should be faster than having to cast to int all the time - initPaginatedValues(1, values) + initPaginatedValues(1, &values) currChat := getChat(values[0]) diff --git a/go-src/windowsHelpers.go b/go-src/windowsHelpers.go index d4ff90c..c94616c 100644 --- a/go-src/windowsHelpers.go +++ b/go-src/windowsHelpers.go @@ -58,9 +58,9 @@ func routinePaginatedSubwindow(messages *[]string, updateMessages func(*[]string } } -func initPaginatedValues(defaultLength int, values []string) { - if len(values) == defaultLength { - values = append(append(values, "."), "") +func initPaginatedValues(defaultLength int, values *[]string) { + if len(*values) == defaultLength { + *values = append(append(*values, "."), "") } } -- cgit v1.2.3