fixes #15207 [backport:1.2]

This commit is contained in:
Araq
2020-08-26 14:31:00 +02:00
committed by Andreas Rumpf
parent 71025b8a8f
commit 40969296e9

View File

@@ -776,25 +776,20 @@ when defined(windows):
## ``true`` otherwise.
password.string.setLen(0)
stdout.write(prompt)
while true:
let c = getch()
case c.char
of '\r', chr(0xA):
break
of '\b':
# ensure we delete the whole UTF-8 character:
var i = 0
var x = 1
while i < password.len:
x = runeLenAt(password.string, i)
inc i, x
password.string.setLen(max(password.len - x, 0))
of chr(0x0):
# modifier key - ignore - for details see
# https://github.com/nim-lang/Nim/issues/7764
continue
else:
password.string.add(toUTF8(c.Rune))
let hi = createFileA("CONIN$",
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0)
var mode = DWORD 0
discard getConsoleMode(hi, addr mode)
let origMode = mode
const
ENABLE_PROCESSED_INPUT = 1
ENABLE_ECHO_INPUT = 4
mode = (mode or ENABLE_PROCESSED_INPUT) and not ENABLE_ECHO_INPUT
discard setConsoleMode(hi, mode)
result = readLine(stdin, password)
discard setConsoleMode(hi, origMode)
discard closeHandle(hi)
stdout.write "\n"
else: