mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Force IRB::Color to recognize TERM
Closes: https://github.com/ruby/ruby/pull/2150
This commit is contained in:
parent
022cbb278f
commit
0c54d2e2c7
1 changed files with 19 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: false
|
||||
require 'test/unit'
|
||||
require 'irb/color'
|
||||
require 'stringio'
|
||||
|
||||
module TestIRB
|
||||
class TestColor < Test::Unit::TestCase
|
||||
|
@ -23,7 +24,7 @@ module TestIRB
|
|||
'ERB.new("a#{nil}b", trim_mode: "-")' => "#{BLUE}#{BOLD}#{UNDERLINE}ERB#{CLEAR}.new(#{RED}\"#{CLEAR}#{RED}a#{CLEAR}#{RED}\#{#{CLEAR}#{CYAN}#{BOLD}nil#{CLEAR}#{RED}}#{CLEAR}#{RED}b#{CLEAR}#{RED}\"#{CLEAR}, #{MAGENTA}trim_mode:#{CLEAR} #{RED}\"#{CLEAR}#{RED}-#{CLEAR}#{RED}\"#{CLEAR})",
|
||||
"# comment" => "#{BLUE}#{BOLD}# comment#{CLEAR}",
|
||||
}.each do |code, result|
|
||||
assert_equal(result, IRB::Color.colorize_code(code))
|
||||
assert_equal(result, with_term { IRB::Color.colorize_code(code) })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,5 +41,22 @@ module TestIRB
|
|||
assert_equal(result, IRB::Color.inspect_colorable?(object))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_term
|
||||
stdout = $stdout
|
||||
io = StringIO.new
|
||||
def io.tty?; true; end
|
||||
$stdout = io
|
||||
|
||||
env = ENV.to_h.dup
|
||||
ENV['TERM'] = 'xterm-256color'
|
||||
|
||||
yield
|
||||
ensure
|
||||
$stdout = stdout
|
||||
ENV.replace(env) if env
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue