diff --git a/config.go b/config.go index 1167408..f8f1d94 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "fmt" "github.com/BurntSushi/toml" "os" @@ -40,12 +41,11 @@ func setupConfig(rerun bool) (*Config, error) { _, statErr := os.Stat(cfgPath) if rerun || os.IsNotExist(statErr) { fmt.Println("Enter the path to your Wow directory below. Use the full path without shortcuts like '~' (ex: /home/user/epoch):") - var s string - _, err = fmt.Scanln(&s) + s, err := readLine() if err != nil { return nil, fmt.Errorf("unable to read input: %v", err) } - newConfig.WowDir = strings.TrimSpace(s) + newConfig.WowDir = s fmt.Println() p, err := promptYesNo(fmt.Sprintf("Do you want to use epochcli to launch Wow? Select No if you plan on using a launcher tool like Lutris (y/n): ")) @@ -115,14 +115,12 @@ func setupConfig(rerun bool) (*Config, error) { } func promptYesNo(prompt string) (bool, error) { - var s string for { fmt.Print(prompt) - _, err := fmt.Scanf("%s", &s) + s, err := readLine() if err != nil { return false, fmt.Errorf("unable to read input: %v", err) } - s := strings.TrimSpace(s) if s == "y" || s == "Y" { return true, nil @@ -146,3 +144,12 @@ func input(prompt string) (string, error) { } return strings.TrimSpace(s), nil } + +func readLine() (string, error) { + reader := bufio.NewReader(os.Stdin) + in, err := reader.ReadString('\n') + if err != nil { + return "", fmt.Errorf("unable to read input: %v", err) + } + return strings.TrimSpace(in), nil +}