|
@@ -51,6 +51,9 @@ def _kb_hold_protect_unix():
|
|
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
|
break
|
|
|
|
|
|
+# Use os.read(), not file.read(), to get a variable number of bytes without blocking.
|
|
|
+# Request 5 bytes to cover escape sequences generated by F1, F2, .. Fn keys (5 bytes)
|
|
|
+# as well as UTF8 chars (4 bytes max).
|
|
|
def _get_keypress_unix(prompt='',immed_chars='',prehold_protect=True):
|
|
|
msg_r(prompt)
|
|
|
timeout = float(0.3)
|
|
@@ -60,7 +63,7 @@ def _get_keypress_unix(prompt='',immed_chars='',prehold_protect=True):
|
|
|
while True:
|
|
|
# Protect against held-down key before read()
|
|
|
key = select([sys.stdin], [], [], timeout)[0]
|
|
|
- ch = sys.stdin.read(1)
|
|
|
+ ch = os.read(fd,5)
|
|
|
if prehold_protect:
|
|
|
if key: continue
|
|
|
if immed_chars == 'ALL' or ch in immed_chars: break
|
|
@@ -71,21 +74,19 @@ def _get_keypress_unix(prompt='',immed_chars='',prehold_protect=True):
|
|
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
|
return ch
|
|
|
|
|
|
-def _get_keypress_unix_stub(prompt='',immed_chars='',prehold_protect=None):
|
|
|
- msg_r(prompt)
|
|
|
- return sys.stdin.read(1)
|
|
|
-
|
|
|
-# Use os.read(), not file.read(), to get less than the requested number of characters without blocking.
|
|
|
def _get_keypress_unix_raw(prompt='',immed_chars='',prehold_protect=None):
|
|
|
msg_r(prompt)
|
|
|
fd = sys.stdin.fileno()
|
|
|
old = termios.tcgetattr(fd)
|
|
|
tty.setcbreak(fd)
|
|
|
- # 5 because escape sequences (F1, F2, .. Fn) have 5 bytes max. UTF8 chars have 4 bytes max
|
|
|
ch = os.read(fd,5)
|
|
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
|
return ch
|
|
|
|
|
|
+def _get_keypress_unix_stub(prompt='',immed_chars='',prehold_protect=None):
|
|
|
+ msg_r(prompt)
|
|
|
+ return sys.stdin.read(1)
|
|
|
+
|
|
|
def _kb_hold_protect_mswin():
|
|
|
|
|
|
timeout = float(0.5)
|