[PD2] Code almost all done. Need to add logout and change help message
Co-authored-by: tsousa111 <tiagao2001@hotmail.com>
This commit is contained in:
parent
e2c3d75223
commit
6f8219d991
12 changed files with 123 additions and 212 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func readStdin(message string) string {
|
||||
|
@ -14,6 +13,10 @@ func readStdin(message string) string {
|
|||
return scanner.Text()
|
||||
}
|
||||
|
||||
func printInfo(info string){
|
||||
fmt.Println(info)
|
||||
}
|
||||
|
||||
func printError(err string) {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
@ -27,10 +30,10 @@ func showHelp() {
|
|||
fmt.Println("help: Imprime instruções de uso do programa.")
|
||||
}
|
||||
|
||||
func showMessagesInfo(page int, numPages int, messages []ClientMessageInfo) int {
|
||||
func showMessagesInfo(page int, numPages int, messages []ClientMessageInfo) {
|
||||
if messages == nil {
|
||||
fmt.Println("No unread messages in the queue")
|
||||
return 0
|
||||
return
|
||||
}
|
||||
for _, message := range messages {
|
||||
if message.decryptError != nil {
|
||||
|
@ -41,47 +44,6 @@ func showMessagesInfo(page int, numPages int, messages []ClientMessageInfo) int
|
|||
}
|
||||
}
|
||||
fmt.Printf("Page %v/%v\n", page, numPages)
|
||||
return messagesInfoPageNavigation(page, numPages)
|
||||
}
|
||||
|
||||
func messagesInfoPageNavigation(page int, numPages int) int {
|
||||
var action string
|
||||
|
||||
switch page {
|
||||
case 1:
|
||||
if page == numPages {
|
||||
return 0
|
||||
} else {
|
||||
action = readStdin("Actions: quit/next")
|
||||
}
|
||||
case numPages:
|
||||
action = readStdin("Actions: prev/quit")
|
||||
default:
|
||||
action = readStdin("prev/quit/next")
|
||||
}
|
||||
|
||||
switch strings.ToLower(action) {
|
||||
case "prev":
|
||||
if page == 1 {
|
||||
fmt.Println("Unavailable action: Already in first page")
|
||||
messagesInfoPageNavigation(page, numPages)
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
case "quit":
|
||||
return 0
|
||||
case "next":
|
||||
if page == numPages {
|
||||
fmt.Println("Unavailable action: Already in last page")
|
||||
messagesInfoPageNavigation(page, numPages)
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
default:
|
||||
fmt.Println("Unknown action")
|
||||
messagesInfoPageNavigation(page, numPages)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func showMessage(message ClientMessage) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue