diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 13:16:48 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-07-22 13:16:48 +0300 |
| commit | ffc2c1273183b488de9cc4fc282379c2a042bd6d (patch) | |
| tree | 96be6929f43e8032976f976a991f9c56ae7cb971 /go-src/windows.go | |
| parent | 1f15111c6e44ea7e855fadc187a19234640e161c (diff) | |
| download | ctfc-ffc2c1273183b488de9cc4fc282379c2a042bd6d.tar ctfc-ffc2c1273183b488de9cc4fc282379c2a042bd6d.tar.gz ctfc-ffc2c1273183b488de9cc4fc282379c2a042bd6d.zip | |
Improved printing multiple fields workflow, implemented routine pagination in chats window, implemented routine pagination supoprt for help line
Diffstat (limited to 'go-src/windows.go')
| -rw-r--r-- | go-src/windows.go | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/go-src/windows.go b/go-src/windows.go index b3af04e..744e672 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -20,7 +20,9 @@ func StartupWindow(...string) { inputAction{"L", loginWindow, nil}, inputAction{"R", registerWindow, nil}, ) - if !handled { + if handled != nil { + defer handled() + } else { defer showError(invalidCommand, StartupWindow) } } @@ -71,24 +73,43 @@ func registerWindow(values ...string) { func chatsWindow(values ...string) { csi.ClearScreen() + if len(values) == 0 { + values = append(append(values, ""), ".") + } + ui.NormalBox(true, "Direct Messages", "Account", "Logout") + allChats := getAllChats() - ui.NumberedFields(allChats...) - ui.PageField(0, 0) - ui.EmptyLine() - if len(values) > 0 { - if values[0] == "ShowHelp" { - ui.TextField("Chats page options: [(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(C) for create chat/(name) for go to chat room by name/(number) for go to chat room by number/(H)elp]") - } + customLinesBelow := 2 + if values[0] == "ShowHelp" { + customLinesBelow++ + } + ui.EmptyLines(pageSize + 1 + customLinesBelow) + + lastLine := -1 + go routinePaginatedSubwindow(&allChats, + func(s *[]string) { *s = getAllChats() }, + &lastLine, + len(values[1]), + customLinesBelow, + true, + ) + + if values[0] == "ShowHelp" { + ui.TextField("Chats page options: [(D)irect messages/(A)ccount/(L)ogout/(<) for previous page/(>) for next page/(C) for create chat/(name) for go to chat room by name/(number) for go to chat room by number/(H)elp]") } + input := ui.InputField("[D/A/L/</>/C/E/name/number/H]") handled := handleInputActions(input, true, inputAction{"C", createChatWindow, nil}, - inputAction{"H", chatsWindow, []string{"ShowHelp"}}, + inputAction{"H", chatsWindow, []string{"ShowHelp", values[1]}}, ) - if !handled { + + if handled != nil { + defer handled() + } else { // 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]) @@ -96,6 +117,7 @@ func chatsWindow(values ...string) { defer showError(invalidCommand, chatsWindow) } } + lastLine = -2 } func createChatWindow(values ...string) { @@ -124,31 +146,49 @@ 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 if len(values) == 1 { - values = append(values, ".") + values = append(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 + ")") + ui.TextFields( + currChat.Name+" : "+currChat.Description, + "Brought to you by "+currChat.Owner.Name+" ("+currChat.Owner.Username+")", + ) + customLinesBelow := 2 // One empty line to separate the "Brought to you by" line // with the chat messages, and then empty line for each chat message - for i := 0; i <= pageSize+1; i++ { - ui.EmptyLine() + ui.EmptyLines(pageSize + 1 + customLinesBelow) + + if values[2] == "ShowHelp" { + customLinesBelow++ } - lastLine := 0 + lastLine := -1 go routinePaginatedSubwindow(&currChat.Messages, func(s *[]string) { *s = getChat(values[0]).Messages }, &lastLine, len(values[1]), + customLinesBelow, + false, ) + if values[2] == "ShowHelp" { + ui.TextField("Help info") + values[2] = "" + } + input := ui.InputField("Message or [C/D/A/L/</>/H]") - handled := handleInputActions(input, true) - if !handled { + handled := handleInputActions(input, true, + inputAction{"H", chatWindow, []string{values[0], values[1], "ShowHelp"}}, + ) + + if handled != nil { + defer handled() + } else { switch input { case ">": // If possible, increment to the next page (adds a dot to the end of the string) @@ -168,7 +208,7 @@ func chatWindow(values ...string) { defer chatWindow(values...) } - lastLine = -1 // Practically stops execution of the paginated subwindow routine + lastLine = -2 // Practically stops execution of the paginated subwindow routine } func logoutWindow(...string) { @@ -252,7 +292,7 @@ type inputAction struct { args []string } -func handleInputActions(input string, handleNav bool, ia ...inputAction) bool { +func handleInputActions(input string, handleNav bool, ia ...inputAction) func() { if handleNav { ia = append(ia, inputAction{"C", chatsWindow, nil}, @@ -263,9 +303,8 @@ func handleInputActions(input string, handleNav bool, ia ...inputAction) bool { } for _, v := range ia { if strings.ToLower(input) == strings.ToLower(v.value) { - defer v.execute(v.args...) - return true + return func() { v.execute(v.args...) } } } - return false + return nil } |
