[ruby/irb] Ensure stdout is a TTY before calling winsize

When outputting a (possibly truncated) value, IRB will query the
window size.  However, if IRB was piped to another process, stdout
will no longer be a TTY and will not support the `winsize` method.

This fix ensure that stdout is a TTY.

125de5eeea
This commit is contained in:
Peter Jones 2022-03-24 13:48:27 -07:00 committed by git
parent 846a6bb60f
commit e0bfdb23af
2 changed files with 13 additions and 5 deletions

View file

@ -39,7 +39,7 @@ module IRB
public :gets
def winsize
if instance_variable_defined?(:@stdout)
if instance_variable_defined?(:@stdout) && @stdout.tty?
@stdout.winsize
else
[24, 80]