diff --git a/cmd/clientFunc.go b/cmd/clientFunc.go index f8d2de8..770233f 100644 --- a/cmd/clientFunc.go +++ b/cmd/clientFunc.go @@ -7,13 +7,15 @@ package cmd import ( "bufio" "fmt" - "github.com/jroimartin/gocui" - "github.com/nsf/termbox-go" "log" "net" "os" + "runtime" "strings" "time" + + "github.com/jroimartin/gocui" + "github.com/nsf/termbox-go" ) type Message struct { @@ -92,13 +94,29 @@ func receiveMessage(conn net.Conn) (s string, err error) { return finalMessage, nil } -func sendName(conn net.Conn) { - message, err := bufio.NewReader(os.Stdin).ReadString('\n') +func scanLine() (line string, err error) { + switch runtime.GOOS { + case "linux": + message, err := bufio.NewReader(os.Stdin).ReadString('\n') + if err != nil { + return "", err + } + line = message + case "windows": + message, err := bufio.NewReader(os.Stdin).ReadString('\r') + if err != nil { + return "", err + } + line = message + } + return line, nil +} +func sendName(conn net.Conn) { + message, err := scanLine() if err != nil { log.Fatalf("Error occurred sending message to server: %v\n", err) } - Profile.Username = strings.TrimRight(message, "\n") if _, err := conn.Write([]byte(message)); err != nil {