[ruby/reline] Update Relin::IOGate dinamically when it is needed

(https://github.com/ruby/reline/pull/560)

https://github.com/ruby/reline/commit/4680d1c9e0
This commit is contained in:
tomoya ishida 2023-07-06 05:21:09 +09:00 committed by git
parent 5f07f78e86
commit 6f9d1b4b0f
2 changed files with 15 additions and 0 deletions

View File

@ -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'

View File

@ -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