ruby/lib
Aaron Patterson 89d89fa49d When reading from stdin, put a wrapper around the IO object
The purpose of this commit is to fix Bug #21188.  We need to detect when
stdin has run in to an EOF case.  Unfortunately we can't _call_ the eof
function on IO because it will block.

Here is a short script to demonstrate the issue:

```ruby
x = STDIN.gets
puts x
puts x.eof?
```

If you run the script, then type some characters (but _NOT_ a newline),
then hit Ctrl-D twice, it will print the input string.  Unfortunately,
calling `eof?` will try to read from STDIN again causing us to need a
3rd Ctrl-D to exit the program.

Before introducing the EOF callback to Prism, the input loop looked
kind of like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if str.nil?
    p :DONE
  end
end
```

Which required 3 Ctrl-D to exit.  If we naively changed it to something
like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if STDIN.eof?
    p :DONE
  end
end
```

It would still require 3 Ctrl-D because `eof?` would block.  In this
patch, we're wrapping the IO object, checking the buffer for a newline
and length, and then using that to simulate a non-blocking eof? method.

This commit wraps STDIN and emulates a non-blocking `eof` function.

[Bug #21188]
2025-08-04 12:34:33 -07:00
..
bundler [rubygems/rubygems] Remove unnecessary endless loop detection 2025-07-30 11:19:32 +09:00
cgi Added warning for CGI.parse 2025-06-04 12:47:29 +09:00
did_you_mean [ruby/did_you_mean] Bump version to 2.0.0 2024-12-04 12:32:02 +00:00
erb [ruby/erb] Version 5.0.2 2025-07-15 16:33:00 +00:00
error_highlight [ruby/error_highlight] Ensure first_line and last_line are set 2025-01-29 08:51:42 +00:00
forwardable
net [ruby/net-http] Support pretty_print 2025-06-11 05:04:16 +00:00
open3
optparse Use git ls-files instead of Dir.glob because optparse has optionparser.rb that is outside of lib/optparse directory 2025-07-01 11:50:11 +09:00
prism When reading from stdin, put a wrapper around the IO object 2025-08-04 12:34:33 -07:00
random Freeze Random::Formatter::ALPHANUMERIC and its elements 2024-12-16 20:54:40 +09:00
rubygems [rubygems/rubygems] Restore treating "--" as an unknown platform 2025-07-17 11:07:22 +09:00
syntax_suggest [ruby/syntax_suggest] v2.0.2 2024-11-15 16:09:30 +00:00
unicode_normalize Check Unicode version of the normalization table 2025-04-23 14:14:36 +09:00
uri [ruby/uri] [DOC] Update old use of URI::Parser 2025-07-14 05:11:58 +00:00
yaml [ruby/yaml] Support old version of Psych 2024-10-16 08:49:54 +00:00
bundled_gems.rb Warn to use tsort for Ruby 3.6 that will be released at 2026 2025-07-10 16:48:16 +09:00
bundler.rb [rubygems/rubygems] Load RubyGems extensions in the first place 2025-07-14 11:52:13 +09:00
cgi.rb Fix uplevel for cgi under bundler 2025-05-20 18:22:41 +09:00
delegate.gemspec [ruby/delegate] Bump up required ruby version to 3.0 2024-11-07 02:26:50 +00:00
delegate.rb [ruby/delegate] Bump up v0.4.0 2024-11-07 02:26:50 +00:00
did_you_mean.rb [ruby/did_you_mean] Removed deprecated constants for Ruby 3.4 2024-12-04 12:07:11 +00:00
English.gemspec [ruby/English] Exclude unused files from gem 2025-07-27 15:18:50 +00:00
English.rb
erb.rb [ruby/erb] Support all cgi.gem versions 2025-05-13 17:50:05 +00:00
error_highlight.rb
fileutils.gemspec [ruby/fileutils] Update license files same as ruby/ruby 2024-08-27 00:39:24 +00:00
fileutils.rb [ruby/fileutils] Make ln_s forward target_directory to ln_sr 2025-07-19 15:44:55 +00:00
find.gemspec [ruby/find] find.gemspec: Drop executables dir config 2024-05-17 02:05:31 +00:00
find.rb
forwardable.rb
ipaddr.gemspec [ruby/ipaddr] Drop support for Ruby 2.3 2024-10-23 04:07:30 +00:00
ipaddr.rb [ruby/ipaddr] Added IPAddr#+/- 2025-04-26 11:56:42 +00:00
mkmf.rb Suppress maybe-uninitialized warnings 2025-07-31 23:07:08 +09:00
open-uri.gemspec
open-uri.rb [ruby/open-uri] Bump up v0.5.0 2024-11-06 08:37:52 +00:00
open3.rb
optionparser.rb
optparse.rb [ruby/optparse] Expand literal home paths only 2025-08-03 13:53:27 +00:00
pathname.rb Make Pathname#mkpath builtin 2025-07-15 12:57:18 +02:00
pp.gemspec Fix commit miss [ci skip] 2024-11-12 11:53:01 +09:00
pp.rb Implement Set as a core class 2025-04-26 10:31:11 +09:00
prettyprint.gemspec
prettyprint.rb
prism.rb [ruby/prism] [DOC] Specify markdown mode to RDoc 2025-05-29 04:45:58 +00:00
resolv.gemspec [ruby/resolv] Add spec extensions 2024-09-10 08:33:32 +00:00
resolv.rb [ruby/resolv] v0.6.2 2025-07-08 07:25:26 +00:00
ruby2_keywords.gemspec
rubygems.rb [rubygems/rubygems] Workaround RVM issue when using Bundler <= 2.5.22 2025-07-22 10:01:28 +09:00
securerandom.gemspec [ruby/securerandom] Provide a 'Changelog' link on rubygems.org/gems/securerandom 2025-01-06 01:19:30 +00:00
securerandom.rb [ruby/securerandom] Bump up v0.4.1 2024-12-16 05:43:01 +00:00
shellwords.gemspec [ruby/shellwords] shellwords.gemspec: Avoid configuring exe/ directory 2025-07-28 13:18:05 +00:00
shellwords.rb [ruby/shellwords] Bump up v0.2.2 2024-12-13 00:50:02 +00:00
singleton.gemspec
singleton.rb [ruby/singleton] Bump up v0.3.0 2024-11-08 03:54:21 +00:00
syntax_suggest.rb
tempfile.gemspec
tempfile.rb [ruby/tempfile] [DOC] Fix a typo 2025-06-17 09:41:45 +00:00
time.gemspec
time.rb [ruby/time] [DOC] Make RDoc coverage 100% 2024-11-29 01:39:01 +00:00
timeout.gemspec
timeout.rb [ruby/timeout] Gracefully handle a call to ensure_timeout_thread_created in a signal handler 2025-06-24 20:41:45 +00:00
tmpdir.gemspec [ruby/tmpdir] Bump up v0.3.1 2024-12-17 06:47:52 +00:00
tmpdir.rb [ruby/tmpdir] Move private constants under Dir::Tmpname module 2024-12-16 10:28:10 +00:00
tsort.gemspec [ruby/tsort] Add changelog_uri to gemspec metadata 2025-07-28 20:14:38 +00:00
tsort.rb [ruby/tsort] [DOC] Document constants 2025-07-08 06:11:04 +00:00
un.gemspec
un.rb
uri.rb
weakref.gemspec [ruby/weakref] weakref.gemspec: Drop gemspec config on executables 2025-01-23 00:24:44 +00:00
weakref.rb [ruby/weakref] v0.1.4 2025-06-19 01:53:19 +00:00
yaml.rb [ruby/yaml] Bump up v0.4.0 2024-11-06 07:32:52 +00:00