diff --git a/lib/reline.rb b/lib/reline.rb index ae98224653..85c1d96dd2 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -270,6 +270,7 @@ def get_screen_size Reline::DEFAULT_DIALOG_CONTEXT = Array.new def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination) + Reline.update_iogate Reline::IOGate.with_raw_input do unless confirm_multiline_termination raise ArgumentError.new('#readmultiline needs block to confirm multiline termination') @@ -288,6 +289,7 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination) end def readline(prompt = '', add_hist = false) + Reline.update_iogate inner_readline(prompt, add_hist, false) line = line_editor.line.dup @@ -584,6 +586,18 @@ def self.ungetc(c) def self.line_editor core.line_editor end + + def self.update_iogate + return if core.config.test_mode + + # Need to change IOGate when `$stdout.tty?` change from false to true by `$stdout.reopen` + # Example: rails/spring boot the application in non-tty, then run console in tty. + if ENV['TERM'] != 'dumb' && Reline::IOGate == Reline::GeneralIO && $stdout.tty? + require 'reline/ansi' + remove_const(:IOGate) + const_set(:IOGate, Reline::ANSI) + end + end end require 'reline/general_io' diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index 460fb7872d..33387231b4 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -8,6 +8,7 @@ def call; end end def setup + Reline.send(:test_mode) Reline.output_modifier_proc = nil Reline.completion_proc = nil Reline.prompt_proc = nil