diff options
Diffstat (limited to 'go-src/windows.go')
| -rw-r--r-- | go-src/windows.go | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/go-src/windows.go b/go-src/windows.go index beac8ed..8e75aa7 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -7,8 +7,10 @@ import ( "runtime" "strconv" "strings" + "time" "gitlab.com/Syndamia/ctfc/go-src/ui" + "gitlab.com/Syndamia/ctfc/go-src/utils" ) type window func(...string) @@ -120,11 +122,35 @@ func chatWindow(values ...string) { 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 + ")") - ui.EmptyLine() - for _, v := range currChat.Messages { - ui.TextField(v) + + for i := 0; i <= 15; i++ { + ui.EmptyLine() } - ui.PageField(0, 0) + + 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) + } + }() input := ui.InputField("Message or [C/D/A/L/</>/H]") @@ -133,6 +159,7 @@ func chatWindow(values ...string) { currChat.addMessage(strings.TrimPrefix(input, "\\"), loggedInUser.Username) defer chatWindow(values...) } + lines = -1 } func logoutWindow(...string) { @@ -245,3 +272,16 @@ func clearScreen() { 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) +} |
