fixes #15207 [backport:1.2]
This commit is contained in:
parent
71025b8a8f
commit
40969296e9
1 changed files with 14 additions and 19 deletions
|
|
@ -776,25 +776,20 @@ when defined(windows):
|
||||||
## ``true`` otherwise.
|
## ``true`` otherwise.
|
||||||
password.string.setLen(0)
|
password.string.setLen(0)
|
||||||
stdout.write(prompt)
|
stdout.write(prompt)
|
||||||
while true:
|
let hi = createFileA("CONIN$",
|
||||||
let c = getch()
|
GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0)
|
||||||
case c.char
|
var mode = DWORD 0
|
||||||
of '\r', chr(0xA):
|
discard getConsoleMode(hi, addr mode)
|
||||||
break
|
let origMode = mode
|
||||||
of '\b':
|
const
|
||||||
# ensure we delete the whole UTF-8 character:
|
ENABLE_PROCESSED_INPUT = 1
|
||||||
var i = 0
|
ENABLE_ECHO_INPUT = 4
|
||||||
var x = 1
|
mode = (mode or ENABLE_PROCESSED_INPUT) and not ENABLE_ECHO_INPUT
|
||||||
while i < password.len:
|
|
||||||
x = runeLenAt(password.string, i)
|
discard setConsoleMode(hi, mode)
|
||||||
inc i, x
|
result = readLine(stdin, password)
|
||||||
password.string.setLen(max(password.len - x, 0))
|
discard setConsoleMode(hi, origMode)
|
||||||
of chr(0x0):
|
discard closeHandle(hi)
|
||||||
# modifier key - ignore - for details see
|
|
||||||
# https://github.com/nim-lang/Nim/issues/7764
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
password.string.add(toUTF8(c.Rune))
|
|
||||||
stdout.write "\n"
|
stdout.write "\n"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue