1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-04-11 09:37:09 +00:00

Ignore termios error in getch_noblock(). Fixes #46

This commit is contained in:
Mike Naberezny 2018-10-06 12:50:59 -07:00
parent 3193a348f7
commit 7ed4d95885
2 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,10 @@
1.1.0.dev0 (Next Release)
-------------------------
- Added a workaround to ignore an error ``Error: <class 'termios.error'>,
(25, 'Inappropriate ioctl for device')`` that may occur on some systems
when reading character input. Based on a patch by Marko Lauke.
1.1.0 (2018-07-01)
------------------

View File

@ -49,9 +49,14 @@ else:
character. If no character is available, an empty string is returned.
"""
char = ''
fd = stdin.fileno()
oldterm = termios.tcgetattr(fd)
try:
oldterm = termios.tcgetattr(fd)
except termios.error: # https://github.com/mnaberez/py65/issues/46
return char
newattr = oldterm[:]
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
@ -60,7 +65,6 @@ else:
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
char = ''
r, w, e = select.select([fd], [], [], 0.1)
if r:
char = stdin.read(1)