summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2020-08-26 14:31:00 +0200
committerAndreas Rumpf <rumpf_a@web.de>2020-08-26 15:27:15 +0200
commit40969296e91f4e2b9ac7342a6bb301ef0ea3bda4 (patch)
tree8ae1e390c55f2fc5fa5a84a4e04aff2bf481a087 /lib/pure
parent71025b8a8f4ebbb58555de74565ce006a9c17444 (diff)
downloadNim-40969296e91f4e2b9ac7342a6bb301ef0ea3bda4.tar.gz
fixes #15207 [backport:1.2]
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/terminal.nim33
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index 99a333cc6..968d6bd9a 100644
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -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: