File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 12
12
13
13
14
14
def create_input (stdin : Optional [TextIO ] = None ) -> Input :
15
- stdin = stdin or sys .stdin
16
-
15
+ """
16
+ Create the appropriate `Input` object for the current os/environment.
17
+ """
17
18
if is_windows ():
18
19
from .win32 import Win32Input
19
20
20
- return Win32Input (stdin )
21
+ return Win32Input (stdin or sys . stdin )
21
22
else :
22
23
from .vt100 import Vt100Input
23
24
25
+ # If no input TextIO is given, use stdin/stdout.
26
+ if stdin is None :
27
+ # Try stdin first, if it's a TTY.
28
+ if sys .stdin .isatty ():
29
+ stdin = sys .stdin
30
+ # If stdin is not a TTY, it's possible we're piping something into
31
+ # stdin. Use stdout instead if stdout is a TTY. (We can actually
32
+ # use stdout to read input from, this is how a $PAGER works.)
33
+ elif sys .stdout .isatty ():
34
+ stdin = sys .stdout
35
+ # If stdout is also not a tty, then use stdin. (This will print a
36
+ # "Input is not a terminal" warning in `Vt100Input`.)
37
+ else :
38
+ stdin = sys .stdin
39
+
24
40
return Vt100Input (stdin )
25
41
26
42
You can’t perform that action at this time.
0 commit comments