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 1
1
import sys
2
2
import termios
3
- import tty
4
3
5
4
6
5
# Initially taken from:
7
6
# http://code.activestate.com/recipes/134892/
8
7
# Thanks to Danny Yoo
8
+ # more infos from:
9
+ # https://gist.github.com/michelbl/efda48b19d3e587685e3441a74457024
10
+ # Thanks to Michel Blancard
9
11
def readchar () -> str :
10
12
"""Reads a single character from the input stream.
11
13
Blocks until a character is available."""
12
14
13
15
fd = sys .stdin .fileno ()
14
16
old_settings = termios .tcgetattr (fd )
17
+ term = termios .tcgetattr (fd )
15
18
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
+
17
22
ch = sys .stdin .read (1 )
18
23
finally :
19
24
termios .tcsetattr (fd , termios .TCSADRAIN , old_settings )
Original file line number Diff line number Diff line change 3
3
4
4
if sys .platform .startswith ("linux" ):
5
5
import termios
6
- import tty
7
6
8
7
9
8
# ignore all tests in this folder if not on linux
@@ -33,13 +32,9 @@ def mock_tcgetattr(fd):
33
32
def mock_tcsetattr (fd , TCSADRAIN , old_settings ):
34
33
return None
35
34
36
- def mock_setraw (fd ):
37
- return None
38
-
39
35
mock = mocked_stdin ()
40
36
with pytest .MonkeyPatch .context () as mp :
41
37
mp .setattr (sys .stdin , "read" , mock .read )
42
38
mp .setattr (termios , "tcgetattr" , mock_tcgetattr )
43
39
mp .setattr (termios , "tcsetattr" , mock_tcsetattr )
44
- mp .setattr (tty , "setraw" , mock_setraw )
45
40
yield mock
You can’t perform that action at this time.
0 commit comments