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/windowsHelpers.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/windowsHelpers.go')
| -rw-r--r-- | go-src/windowsHelpers.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/go-src/windowsHelpers.go b/go-src/windowsHelpers.go new file mode 100644 index 0000000..13cb3c1 --- /dev/null +++ b/go-src/windowsHelpers.go @@ -0,0 +1,70 @@ +package ctfc + +import ( + "fmt" + "os" + "os/exec" + "runtime" + "time" + + "gitlab.com/Syndamia/ctfc/go-src/ui" + "gitlab.com/Syndamia/ctfc/go-src/utils" +) + +func routinePaginatedSubwindow(messages *[]string, updateMessages func(*[]string), lastLine *int, page int) { + for *lastLine > -1 { + if *lastLine == len(*messages)-1 { + updateMessages(messages) + continue + } + + *lastLine = len(*messages) - 1 + fmt.Print("\033[s") + + moveCursorUp(utils.PageSize + 2) + + pageMessages := utils.Paginate(page, *messages...) + for i := 0; i < utils.PageSize-len(pageMessages); i++ { + ui.EmptyLine() + } + for _, v := range pageMessages { + fmt.Print("\033[K") + ui.TextField(v) + } + + ui.PageField(page, utils.TotalPages(len(*messages))) + + fmt.Print("\033[u") + time.Sleep(500 * time.Millisecond) + } +} + +var clearNext = true + +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) +} |
