Proper tty.setcbreak() replacement requires blocking until at least

one char arrives
This commit is contained in:
anatoly techtonik 2013-07-25 13:41:17 +03:00
parent 7d14542093
commit 56b00e1c33
1 changed files with 3 additions and 1 deletions

View File

@ -197,7 +197,7 @@ def getch():
import sys, termios
fd = sys.stdin.fileno()
# save old terminal settings, because we are changing them
# save old terminal settings
old_settings = termios.tcgetattr(fd)
try:
# change terminal settings - turn off canonical mode and echo
@ -206,6 +206,8 @@ def getch():
newattr = list(old_settings)
newattr[3] &= ~termios.ICANON
newattr[3] &= ~termios.ECHO
newattr[6][termios.VMIN] = 1 # block until one char received
newattr[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, newattr)
ch = sys.stdin.read(1)