ruby-changes:55534
From: Takashi <ko1@a...>
Date: Fri, 26 Apr 2019 01:15:44 +0900 (JST)
Subject: [ruby-changes:55534] Takashi Kokubun:5fe99aefd3 (trunk): Support highlighting Regexp in inspect
https://git.ruby-lang.org/ruby.git/commit/?id=5fe99aefd3 From 5fe99aefd39ce535f658aabd0ca6e2265348d314 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Fri, 26 Apr 2019 01:15:30 +0900 Subject: Support highlighting Regexp in inspect diff --git a/lib/irb/color.rb b/lib/irb/color.rb index 40e84e1..c18739c 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -28,8 +28,8 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L28 on_kw: [[GREEN], [Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME]], on_label: [[MAGENTA], [Ripper::EXPR_LABELED]], on_qwords_beg: [[RED], [Ripper::EXPR_BEG]], - on_regexp_beg: [[RED], [Ripper::EXPR_BEG]], - on_regexp_end: [[RED], [Ripper::EXPR_BEG]], + on_regexp_beg: [[RED, BOLD], [Ripper::EXPR_BEG]], + on_regexp_end: [[RED, BOLD], [Ripper::EXPR_BEG]], on_symbeg: [[BLUE, BOLD], [Ripper::EXPR_FNAME]], on_tstring_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]], on_tstring_content: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_ARG, Ripper::EXPR_CMDARG]], @@ -47,7 +47,7 @@ module IRB # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/irb/color.rb#L47 obj.all? { |k, v| inspect_colorable?(k) && inspect_colorable?(v) } when Array obj.all? { |o| inspect_colorable?(o) } - when String, Symbol, Integer, Float, FalseClass, TrueClass, NilClass + when String, Symbol, Regexp, Integer, Float, FalseClass, TrueClass, NilClass true else false diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index d5f9286..601b7a2 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -23,6 +23,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L23 "def self.foo; bar; end" => "#{GREEN}def#{CLEAR} #{CYAN}#{BOLD}self#{CLEAR}.#{BLUE}#{BOLD}foo#{CLEAR}; bar; #{GREEN}end#{CLEAR}", '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}", + '/r#{e}g/' => "#{RED}#{BOLD}/#{CLEAR}#{RED}r#{CLEAR}#{RED}\#{#{CLEAR}e}#{RED}g#{CLEAR}#{RED}#{BOLD}/#{CLEAR}", }.each do |code, result| assert_equal(result, with_term { IRB::Color.colorize_code(code) }) end @@ -34,6 +35,7 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_color.rb#L35 2.3 => true, ['foo', :bar] => true, { a: 4 } => true, + /reg/ => true, Object.new => false, Struct.new(:a) => false, Struct.new(:a).new(1) => false, -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/