[PD1] Cleaned up protocol,database and receiving multiple messageInfos
This commit is contained in:
parent
4c141bbc6e
commit
f3cf9cfc40
6 changed files with 347 additions and 231 deletions
|
@ -4,10 +4,11 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func readMessageBody() string {
|
||||
fmt.Println("Enter message content (limited to 1000 bytes):")
|
||||
func readStdin(message string) string {
|
||||
fmt.Println(message)
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Scan()
|
||||
// FIX: make sure this doesnt die
|
||||
|
@ -36,15 +37,63 @@ func showHelp() {
|
|||
fmt.Println("help: Imprime instruções de uso do programa.")
|
||||
}
|
||||
|
||||
func showMessagesInfo(messages []ClientMessageInfo) {
|
||||
func showMessagesInfo(page int, numPages int, messages []ClientMessageInfo) int {
|
||||
if messages == nil {
|
||||
fmt.Println("No unread messages in the queue")
|
||||
return 0
|
||||
}
|
||||
for _, message := range messages {
|
||||
fmt.Printf("%v:%v:%v:%v\n", message.Num, message.FromUID, message.Timestamp, message.Subject)
|
||||
}
|
||||
fmt.Printf("Page %v/%v\n",page,numPages)
|
||||
return messagesInfoPageNavigation(page, numPages)
|
||||
}
|
||||
|
||||
func showMessage(message ClientMessage) {
|
||||
fmt.Printf("From:%v\n", message.FromUID)
|
||||
fmt.Printf("To:%v\n", message.ToUID)
|
||||
fmt.Printf("Subject:%v\n", message.Subject)
|
||||
fmt.Printf("Body:%v\n", message.Body)
|
||||
func messagesInfoPageNavigation(page int, numPages int) int {
|
||||
var action string
|
||||
|
||||
switch page {
|
||||
case 1:
|
||||
if page == numPages {
|
||||
action = readStdin("Actions: quit")
|
||||
} 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) {
|
||||
fmt.Printf("From: %s\n", message.FromUID)
|
||||
fmt.Printf("To: %s\n", message.ToUID)
|
||||
fmt.Printf("Subject: %s\n", message.Subject)
|
||||
fmt.Printf("Body: %s\n", message.Body)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue