|
@@ -7,6 +7,7 @@ package terminal
|
7
|
7
|
import (
|
8
|
8
|
"bytes"
|
9
|
9
|
"io"
|
|
10
|
+ "runtime"
|
10
|
11
|
"strconv"
|
11
|
12
|
"sync"
|
12
|
13
|
"unicode/utf8"
|
|
@@ -939,6 +940,8 @@ func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) {
|
939
|
940
|
// readPasswordLine reads from reader until it finds \n or io.EOF.
|
940
|
941
|
// The slice returned does not include the \n.
|
941
|
942
|
// readPasswordLine also ignores any \r it finds.
|
|
943
|
+// Windows uses \r as end of line. So, on Windows, readPasswordLine
|
|
944
|
+// reads until it finds \r and ignores any \n it finds during processing.
|
942
|
945
|
func readPasswordLine(reader io.Reader) ([]byte, error) {
|
943
|
946
|
var buf [1]byte
|
944
|
947
|
var ret []byte
|
|
@@ -947,10 +950,20 @@ func readPasswordLine(reader io.Reader) ([]byte, error) {
|
947
|
950
|
n, err := reader.Read(buf[:])
|
948
|
951
|
if n > 0 {
|
949
|
952
|
switch buf[0] {
|
|
953
|
+ case '\b':
|
|
954
|
+ if len(ret) > 0 {
|
|
955
|
+ ret = ret[:len(ret)-1]
|
|
956
|
+ }
|
950
|
957
|
case '\n':
|
951
|
|
- return ret, nil
|
|
958
|
+ if runtime.GOOS != "windows" {
|
|
959
|
+ return ret, nil
|
|
960
|
+ }
|
|
961
|
+ // otherwise ignore \n
|
952
|
962
|
case '\r':
|
953
|
|
- // remove \r from passwords on Windows
|
|
963
|
+ if runtime.GOOS == "windows" {
|
|
964
|
+ return ret, nil
|
|
965
|
+ }
|
|
966
|
+ // otherwise ignore \r
|
954
|
967
|
default:
|
955
|
968
|
ret = append(ret, buf[0])
|
956
|
969
|
}
|