Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reline/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.decide_io_gate
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
require 'reline/io/windows'
io = Reline::Windows.new
if io.msys_tty?
if io.msys_tty? || !STDIN.tty?
Reline::ANSI.new
else
io
Expand Down
28 changes: 28 additions & 0 deletions test/reline/test_reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ def test_dumb_terminal
assert_match(/#<Reline::Dumb/, out.chomp)
end

def test_readline_reads_piped_stdin
out = readline_from_piped_stdin("input\n")
assert_include(out, { result: 'input' }.inspect)
end

def test_readline_returns_nil_on_piped_stdin_eof
out = readline_from_piped_stdin("")
assert_include(out, { result: nil }.inspect)
end

def test_read_eof_returns_input
pend if win?
lib = File.expand_path("../../lib", __dir__)
Expand Down Expand Up @@ -460,6 +470,24 @@ def win?
/mswin|mingw/.match?(RUBY_PLATFORM)
end

def readline_from_piped_stdin(stdin)
lib = File.expand_path("../../lib", __dir__)
code = <<~'RUBY'
require 'timeout'
begin
p result: Timeout.timeout(3) { Reline.readline('>') }
rescue Timeout::Error
puts 'timeout'
end
RUBY

IO.popen([Reline.test_rubybin, "-I#{lib}", "-rreline", "-e", code], "r+") do |io|
io.write stdin
io.close_write
io.read
end
end

def test_tty_ambiguous_width
omit unless defined?(PTY)
ruby_file = Tempfile.create('rubyfile')
Expand Down
Loading