Fix windows version being unable to take input
This commit is contained in:
parent
b6e133c608
commit
a615cb9194
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue