diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-09-11 15:30:28 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-09-11 15:30:28 +0300 |
| commit | 636ba9a01f7f4c7bbd4c40f65d2d8d00d27d3564 (patch) | |
| tree | bc7d8e17bb678d7d7d5811bee2e32cc9604aadf9 /go-src/windowsHelpers.go | |
| parent | 695dc46d540befe8486eb647c60d08ab0236fa60 (diff) | |
| download | ctfc-636ba9a01f7f4c7bbd4c40f65d2d8d00d27d3564.tar ctfc-636ba9a01f7f4c7bbd4c40f65d2d8d00d27d3564.tar.gz ctfc-636ba9a01f7f4c7bbd4c40f65d2d8d00d27d3564.zip | |
Abstracted if-else logic for changing page and entering number/text input value in chats page
Diffstat (limited to 'go-src/windowsHelpers.go')
| -rw-r--r-- | go-src/windowsHelpers.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/go-src/windowsHelpers.go b/go-src/windowsHelpers.go index 9b1d2d9..761e0d2 100644 --- a/go-src/windowsHelpers.go +++ b/go-src/windowsHelpers.go @@ -1,6 +1,7 @@ package ctfc import ( + "strconv" "strings" "time" @@ -89,6 +90,29 @@ func handleInputActions(input string, handleNav bool, ia ...inputAction) func() return nil } +func handleComplexInputActions(input string, allValues []string, nameSep string, pageArgument *string, currentWindow window, singleValueWindow window, existsCheck func(string) bool) { + // If user input is number, navigate to chat of given number, else show error + if chatI, err := strconv.Atoi(input); chatI >= 0 && chatI <= len(allValues) && err == nil { + defer singleValueWindow(strings.Split(allValues[utils.MaxInt(len(allValues)-pageSize*len(*pageArgument), 0)+chatI-1], " : ")[0]) + } else if input == ">" && pageArgument != nil { + // If possible, increment to the next page (adds a dot to the end of the string) + if len(*pageArgument) < totalPages(len(allValues)) { + *pageArgument += "." + } + defer currentWindow(allValues...) + } else if input == "<" { + // If possible, decrement to the previous page (removes a dot from the string) + if len(*pageArgument) > 1 { + utils.StrShortenRight(*&pageArgument, 1) + } + defer currentWindow(allValues...) + } else if existsCheck(input) { + defer singleValueWindow(input) + } else { + defer showError(invalidCommand, currentWindow) + } +} + /* Form */ type formInput struct { |
