Skip to content

Commit 703dea5

Browse files
dsblankjonathanslenders
authored andcommitted
Check to see if stdout is still a tty when we get_size (prompt-toolkit#1021)
* Check to see if stdout is still a tty when we get_size The sys.stdout may change over time from a tty to a non-tty. Can happen when putting a file-capture on the fileno.
1 parent b457f8b commit 703dea5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

prompt_toolkit/output/vt100.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,9 @@ def from_pty(cls, stdout: TextIO, term: Optional[str] = None) -> "Vt100_Output":
446446
# Normally, this requires a real TTY device, but people instantiate
447447
# this class often during unit tests as well. For convenience, we print
448448
# an error message, use standard dimensions, and go on.
449-
isatty = stdout.isatty()
450449
fd = stdout.fileno()
451450

452-
if not isatty and fd not in cls._fds_not_a_terminal:
451+
if not stdout.isatty() and fd not in cls._fds_not_a_terminal:
453452
msg = "Warning: Output is not a terminal (fd=%r).\n"
454453
sys.stderr.write(msg % fd)
455454
cls._fds_not_a_terminal.add(fd)
@@ -460,7 +459,7 @@ def get_size() -> Size:
460459
# https://github.com/ipython/ipython/issues/10071
461460
rows, columns = (None, None)
462461

463-
if isatty:
462+
if stdout.isatty():
464463
rows, columns = _get_size(stdout.fileno())
465464
return Size(rows=rows or 24, columns=columns or 80)
466465

0 commit comments

Comments
 (0)