summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2023-07-06 05:21:09 +0900
committergit <svn-admin@ruby-lang.org>2023-07-05 20:21:13 +0000
commit6f9d1b4b0f8938c42aa767577c7c6761ed9de64a (patch)
treea13ddb24d406b472ac32578e098af6eb89647e7c
parent5f07f78e8698a2802dd544dc098b0c1d8080e702 (diff)
[ruby/reline] Update Relin::IOGate dinamically when it is needed
(https://github.com/ruby/reline/pull/560) https://github.com/ruby/reline/commit/4680d1c9e0
-rw-r--r--lib/reline.rb14
-rw-r--r--test/reline/test_reline.rb1
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index 7776bf4726..8da614aa2b 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -266,6 +266,7 @@ module Reline
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')
@@ -284,6 +285,7 @@ module Reline
end
def readline(prompt = '', add_hist = false)
+ Reline.update_iogate
inner_readline(prompt, add_hist, false)
line = line_editor.line.dup
@@ -580,6 +582,18 @@ module Reline
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 @@ class Reline::Test < Reline::TestCase
end
def setup
+ Reline.send(:test_mode)
Reline.output_modifier_proc = nil
Reline.completion_proc = nil
Reline.prompt_proc = nil