mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 12:52:04 +00:00
Handle Ctrl-C in masked input
This commit is contained in:
1 parent
d9f76ee668
commit
c0a6187478
2 files changed
+38
No files matched your search
@@ -58,6 +58,8 @@ def _masked_input_windows(prompt: str) -> str:
|
||||
buffer: list[str] = []
|
||||
while True:
|
||||
ch = msvcrt.getwch()
|
||||
if ch == "\x03":
|
||||
raise KeyboardInterrupt
|
||||
if ch in ("\r", "\n"):
|
||||
sys.stdout.write("\n")
|
||||
return "".join(buffer)
|
||||
@@ -85,6 +87,8 @@ def _masked_input_posix(prompt: str) -> str:
|
||||
tty.setraw(fd)
|
||||
while True:
|
||||
ch = sys.stdin.read(1)
|
||||
if ch == "\x03":
|
||||
raise KeyboardInterrupt
|
||||
if ch in ("\r", "\n"):
|
||||
sys.stdout.write("\n")
|
||||
return "".join(buffer)
|
||||
@@ -105,6 +109,8 @@ def masked_input(prompt: str) -> str:
|
||||
func = _masked_input_windows if sys.platform == "win32" else _masked_input_posix
|
||||
try:
|
||||
return func(prompt)
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except Exception: # pragma: no cover - fallback when TTY operations fail
|
||||
return input(prompt)
|
||||
|
||||
|
||||
Reference in new issue
Block a user