Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catches Errno::ENODEV and Errno::EBADF in get_screen_size. Closes #690 #702

Merged
merged 2 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def self.get_screen_size
s = [ENV["LINES"].to_i, ENV["COLUMNS"].to_i]
return s if s[0] > 0 && s[1] > 0
[24, 80]
rescue Errno::ENOTTY
rescue Errno::ENOTTY, Errno::ENODEV, Errno::EBADF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding Errno::ENODEV is enough.

The main problem of #690 is that just requiring 'reline' was calling IO#winsize. #703 will fix it.

We need to rescue Errno::ENOTTY and Errno::ENODEV to make reline work in these two scenario.

# For Errno::ENODEV
ruby -rreline -e "Reline.readline" < /dev/null
# For Errno::ENOTTY
ruby -rreline -e "Reline.readline" < file

But for Errno::EBADF, I think we don't need to rescue it. Just like we don't rescue IOError here.

STDIN.close
STDIN.winsize #=> closed stream (IOError)
Reline.readline #=> `tty?': closed stream (IOError)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, just catching Errno::ENOTTY and Errno::ENODEV

[24, 80]
end

Expand Down