File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 11import sys
22import termios
3- import tty
43
54
65# Initially taken from:
76# http://code.activestate.com/recipes/134892/
87# Thanks to Danny Yoo
8+ # more infos from:
9+ # https://gist.github.com/michelbl/efda48b19d3e587685e3441a74457024
10+ # Thanks to Michel Blancard
911def readchar () -> str :
1012 """Reads a single character from the input stream.
1113 Blocks until a character is available."""
1214
1315 fd = sys .stdin .fileno ()
1416 old_settings = termios .tcgetattr (fd )
17+ term = termios .tcgetattr (fd )
1518 try :
16- tty .setraw (sys .stdin .fileno ())
19+ term [3 ] &= ~ (termios .ICANON | termios .ECHO | termios .IGNBRK | termios .BRKINT )
20+ termios .tcsetattr (fd , termios .TCSAFLUSH , term )
21+
1722 ch = sys .stdin .read (1 )
1823 finally :
1924 termios .tcsetattr (fd , termios .TCSADRAIN , old_settings )
Original file line number Diff line number Diff line change 33
44if sys .platform .startswith ("linux" ):
55 import termios
6- import tty
76
87
98# ignore all tests in this folder if not on linux
@@ -33,13 +32,9 @@ def mock_tcgetattr(fd):
3332 def mock_tcsetattr (fd , TCSADRAIN , old_settings ):
3433 return None
3534
36- def mock_setraw (fd ):
37- return None
38-
3935 mock = mocked_stdin ()
4036 with pytest .MonkeyPatch .context () as mp :
4137 mp .setattr (sys .stdin , "read" , mock .read )
4238 mp .setattr (termios , "tcgetattr" , mock_tcgetattr )
4339 mp .setattr (termios , "tcsetattr" , mock_tcsetattr )
44- mp .setattr (tty , "setraw" , mock_setraw )
4540 yield mock
You can’t perform that action at this time.
0 commit comments