diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 09:17:28 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 09:17:28 +0300 |
| commit | 4f9a8920b080e6aee7e19e394654bf879c5759e2 (patch) | |
| tree | 9792318353c048ccb9b8d304dcd35a68d2bfbbfa /go-src/windows.go | |
| parent | 12558447c73da90f63276143f4d6a8796ec2fe7b (diff) | |
| download | ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.tar.gz ctfc-4f9a8920b080e6aee7e19e394654bf879c5759e2.zip | |
Moved chat pagination and real time updating to it's own package, implemeneted pagination navigation
Diffstat (limited to 'go-src/windows.go')
| -rw-r--r-- | go-src/windows.go | 86 |
1 files changed, 25 insertions, 61 deletions
diff --git a/go-src/windows.go b/go-src/windows.go index 8e75aa7..584058a 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -1,13 +1,8 @@ package ctfc import ( - "fmt" - "os" - "os/exec" - "runtime" "strconv" "strings" - "time" "gitlab.com/Syndamia/ctfc/go-src/ui" "gitlab.com/Syndamia/ctfc/go-src/utils" @@ -118,48 +113,47 @@ func createChatWindow(values ...string) { func chatWindow(values ...string) { clearScreen() + if len(values) == 1 { + values = append(values, ".") + } + currChat := getChat(values[0]) ui.NormalBox(true, "Chats", "Direct Messages", "Account", "Logout") ui.TextField(currChat.Name + " : " + currChat.Description) ui.TextField("Brought to you by " + currChat.Owner.Name + " (" + currChat.Owner.Username + ")") - for i := 0; i <= 15; i++ { + for i := 0; i <= 16; i++ { ui.EmptyLine() } - lines := 0 lastLine := 0 - go func() { - for lines > -1 { - if lastLine == len(currChat.Messages)-1 { - currChat = getChat(values[0]) - continue - } - - lastLine = len(currChat.Messages) - 1 - fmt.Print("\033[s") - - moveCursorUp(15 + 2) - - for _, v := range utils.Paginate(1, 15, currChat.Messages...) { - fmt.Print("\033[K") - ui.TextField(v) - } - ui.PageField(1, utils.TotalPages(15, len(currChat.Messages))) - - fmt.Print("\033[u") - time.Sleep(500 * time.Millisecond) - } - }() + go routinePaginatedSubwindow(&currChat.Messages, + func(s *[]string) { *s = getChat(values[0]).Messages }, + &lastLine, + len(values[1]), + ) input := ui.InputField("Message or [C/D/A/L/</>/H]") handled := handleInputActions(input, true) if !handled { - currChat.addMessage(strings.TrimPrefix(input, "\\"), loggedInUser.Username) + switch input { + case ">": + if len(values[1]) < utils.TotalPages(len(currChat.Messages)) { + values[1] += "." + } + case "<": + if len(values[1]) > 1 { + values[1] = values[1][:len(values[1])-1] + } + default: + values[1] = "." + currChat.addMessage(strings.TrimPrefix(input, "\\"), loggedInUser.Username) + } + defer chatWindow(values...) } - lines = -1 + lastLine = -1 } func logoutWindow(...string) { @@ -247,8 +241,6 @@ func handleInputActions(input string, handleNav bool, ia ...inputAction) bool { /* Errors and Clear */ -var clearNext = true - func showError(message string, callback window, callbackData ...string) { clearScreen() @@ -257,31 +249,3 @@ func showError(message string, callback window, callbackData ...string) { defer callback(callbackData...) } - -func clearScreen() { - if !clearNext { - clearNext = true - return - } - - if runtime.GOOS == "windows" { - cmd := exec.Command("cmd", "/c", "cls") - cmd.Stdout = os.Stdout - cmd.Run() - } else { - fmt.Println("\033[2J") - } -} - -func moveCursorUp(times int) { - fmt.Printf("\033[%vA", times) - fmt.Print("\033[E") -} - -func moveCursorDown(times int) { - fmt.Printf("\033[%vB", times) -} - -func moveCursorRight(times int) { - fmt.Printf("\033[%vC", times) -} |
