diff --git a/rbreadline.rb b/rbreadline.rb index c710961..e35408c 100644 --- a/rbreadline.rb +++ b/rbreadline.rb @@ -16,6 +16,7 @@ end module RbReadline require 'etc' + require 'io/console' RL_LIBRARY_VERSION = "5.2" RL_READLINE_VERSION = 0x0502 @@ -1092,6 +1093,9 @@ module RbReadline @current_readline_init_include_level = 0 @current_readline_init_lineno = 0 + # Used in windows + @is_pipe = false + ENV["HOME"] ||= "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}" if !File.directory? ENV["HOME"] raise RuntimeError.new("HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory") @@ -4490,6 +4494,10 @@ module RbReadline end def rl_getc(stream) + # below added as test for whether we're connected to a pipe or a keyboard. + # Pipe connection is probably running under a test suite. + return (stream.getc || EOF rescue EOF) if @is_pipe + while (@kbhit.Call == 0) # If there is no input, yield the processor for other threads sleep(@_keyboard_input_timeout) @@ -4740,6 +4748,7 @@ module RbReadline def readline_internal_charloop() lastc = -1 eof_found = false + @is_pipe = (!@rl_outstream.winsize rescue true) while (!@rl_done) lk = @_rl_last_command_was_kill