Skip to content

Commit

Permalink
Fix io_gate.encoding raises IOError in ruby <= 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Nov 27, 2024
1 parent 5a8da85 commit b375904
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/reline/io/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def initialize

def encoding
@input.external_encoding || Encoding.default_external
rescue IOError
# STDIN.external_encoding raises IOError in Ruby <= 3.0 when STDIN is closed
Encoding.default_external
end

def set_default_key_bindings(config)
Expand Down
5 changes: 4 additions & 1 deletion lib/reline/io/dumb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def encoding
elsif RUBY_PLATFORM =~ /mswin|mingw/
Encoding::UTF_8
else
@input.external_encoding || Encoding::default_external
@input.external_encoding || Encoding.default_external
end
rescue IOError
# STDIN.external_encoding raises IOError in Ruby <= 3.0 when STDIN is closed
Encoding.default_external
end

def set_default_key_bindings(_)
Expand Down

0 comments on commit b375904

Please sign in to comment.