ruby-changes:55532
From: Takashi <ko1@a...>
Date: Fri, 26 Apr 2019 00:47:58 +0900 (JST)
Subject: [ruby-changes:55532] Takashi Kokubun:0c54d2e2c7 (trunk): Force IRB::Color to recognize TERM
https://git.ruby-lang.org/ruby.git/commit/?id=0c54d2e2c7 From 0c54d2e2c7697aa5d6a1315b79c16b88d34f5e81 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Thu, 25 Apr 2019 23:53:57 +0900 Subject: Force IRB::Color to recognize TERM Closes: https://github.com/ruby/ruby/pull/2150 diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 088611c..d5f9286 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -1,6 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L1 # 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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L24 '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 https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L41 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/