From e50aa359de2a419c0a04eaee84a095f602e1ccb1 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 26 May 2019 10:22:57 -0700 Subject: [PATCH] Make the imaginary color on IRB close to pry and sorted the token names alphabetically. --- lib/irb/color.rb | 12 +++++++----- test/irb/test_color.rb | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/irb/color.rb b/lib/irb/color.rb index 852d18414b..767a675bab 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -20,25 +20,27 @@ module IRB # :nodoc: } begin + # Following pry's colors where possible, but sometimes having a compromise like making + # backtick and regexp as red (string's color, because they're sharing tokens). TOKEN_SEQ_EXPRS = { - on_backtick: [[RED], [Ripper::EXPR_BEG]], on_CHAR: [[BLUE, BOLD], [Ripper::EXPR_END]], + on_backtick: [[RED], [Ripper::EXPR_BEG]], on_const: [[BLUE, BOLD, UNDERLINE], [Ripper::EXPR_ARG, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN]], on_embexpr_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_FNAME, Ripper::EXPR_ARG]], on_embexpr_end: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_CMDARG, Ripper::EXPR_ENDFN, Ripper::EXPR_ARG]], on_embvar: [[RED], [Ripper::EXPR_BEG]], + on_float: [[MAGENTA, BOLD], [Ripper::EXPR_END]], on_heredoc_beg: [[RED], [Ripper::EXPR_BEG]], on_heredoc_end: [[RED], [Ripper::EXPR_BEG]], on_ident: [[BLUE, BOLD], [Ripper::EXPR_ENDFN]], + on_imaginary: [[BLUE, BOLD], [Ripper::EXPR_END]], on_int: [[BLUE, BOLD], [Ripper::EXPR_END]], - on_rational: [[BLUE, BOLD], [Ripper::EXPR_END]], - on_float: [[MAGENTA, BOLD], [Ripper::EXPR_END]], - on_imaginary: [[MAGENTA, BOLD], [Ripper::EXPR_END]], on_kw: [[GREEN], [Ripper::EXPR_ARG, Ripper::EXPR_CLASS, Ripper::EXPR_BEG, Ripper::EXPR_END, Ripper::EXPR_FNAME, Ripper::EXPR_MID]], on_label: [[MAGENTA], [Ripper::EXPR_LABELED]], on_label_end: [[RED], [Ripper::EXPR_BEG]], - on_qwords_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_CMDARG]], on_qsymbols_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_CMDARG]], + on_qwords_beg: [[RED], [Ripper::EXPR_BEG, Ripper::EXPR_CMDARG]], + on_rational: [[BLUE, BOLD], [Ripper::EXPR_END]], on_regexp_beg: [[RED, BOLD], [Ripper::EXPR_BEG]], on_regexp_end: [[RED, BOLD], [Ripper::EXPR_BEG]], on_symbeg: [[YELLOW], [Ripper::EXPR_FNAME]], diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb index 3d0eee74d5..f0f0f83aa6 100644 --- a/test/irb/test_color.rb +++ b/test/irb/test_color.rb @@ -26,7 +26,7 @@ module TestIRB "1" => "#{BLUE}#{BOLD}1#{CLEAR}", "2.3" => "#{MAGENTA}#{BOLD}2.3#{CLEAR}", "7r" => "#{BLUE}#{BOLD}7r#{CLEAR}", - "8i" => "#{MAGENTA}#{BOLD}8i#{CLEAR}", + "8i" => "#{BLUE}#{BOLD}8i#{CLEAR}", "['foo', :bar]" => "[#{RED}'#{CLEAR}#{RED}foo#{CLEAR}#{RED}'#{CLEAR}, #{YELLOW}:#{CLEAR}#{YELLOW}bar#{CLEAR}]", "class A; end" => "#{GREEN}class#{CLEAR} #{BLUE}#{BOLD}#{UNDERLINE}A#{CLEAR}; #{GREEN}end#{CLEAR}", "def self.foo; bar; end" => "#{GREEN}def#{CLEAR} #{CYAN}#{BOLD}self#{CLEAR}.#{BLUE}#{BOLD}foo#{CLEAR}; bar; #{GREEN}end#{CLEAR}",