Skip to content

Commit 6a4a1dc

Browse files
committed
feedback: remove stray '\r' on Windows on interactive input
1 parent 8586cde commit 6a4a1dc

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

internal/cli/feedback/terminal.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,18 @@ func InputUserField(prompt string, secret bool) (string, error) {
5555
}
5656

5757
fmt.Fprintf(stdOut, "%s: ", prompt)
58-
var value []byte
59-
var err error
58+
6059
if secret {
61-
value, err = term.ReadPassword(int(os.Stdin.Fd()))
60+
// Read and return a password (no characted echoed on terminal)
61+
value, err := term.ReadPassword(int(os.Stdin.Fd()))
6262
fmt.Fprintln(stdOut)
63-
} else {
64-
value, err = bufio.NewReader(os.Stdin).ReadBytes('\n')
65-
if l := len(value); l > 0 {
66-
value = value[:l-1]
67-
}
68-
}
69-
if err != nil {
70-
panic(err)
63+
return string(value), err
7164
}
7265

73-
return string(value), nil
66+
// Read and return an input line
67+
sc := bufio.NewScanner(os.Stdin)
68+
sc.Scan()
69+
return sc.Text(), sc.Err()
7470
}
7571

7672
// ExitWhenParentProcessEnds waits until the controlling parent process ends and then exits

0 commit comments

Comments
 (0)