Flush stdin and exit stats screen on Enter

This commit is contained in:
thePR0M3TH3AN committed 2025-08-05 13:13:31 -04:00
1 parent d21ad78a02
commit 89cbef1aa4
2 files changed
+44

No files matched your search

+26
View File
@@ -312,7 +312,33 @@ def _display_live_stats(
stats_mgr.reset()
return
# Flush any pending input so an accidental newline doesn't exit immediately
try: # pragma: no cover - depends on platform
import termios
termios.tcflush(sys.stdin, termios.TCIFLUSH)
except Exception:
try: # pragma: no cover - Windows fallback
import msvcrt
while msvcrt.kbhit():
msvcrt.getwch()
except Exception:
pass
while True:
# Break out immediately if the user has already pressed Enter
try: # pragma: no cover - non-interactive environments
import select
ready, _, _ = select.select([sys.stdin], [], [], 0)
if ready:
line = sys.stdin.readline().strip()
if line == "" or line.lower() == "b":
break
except Exception:
pass
if callable(sync_fn):
try:
sync_fn()