File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -270,7 +270,13 @@ def initialize(completor)
270
270
proc do |output , complete : |
271
271
next unless IRB ::Color . colorable?
272
272
lvars = IRB . CurrentContext &.local_variables || [ ]
273
- IRB ::Color . colorize_code ( output , complete : complete , local_variables : lvars )
273
+ if IRB . CurrentContext &.parse_command ( output )
274
+ name , sep , arg = output . split ( /(\s +)/ , 2 )
275
+ arg = IRB ::Color . colorize_code ( arg , complete : complete , local_variables : lvars )
276
+ "#{ IRB ::Color . colorize ( name , [ :BOLD ] ) } \e [m#{ sep } #{ arg } "
277
+ else
278
+ IRB ::Color . colorize_code ( output , complete : complete , local_variables : lvars )
279
+ end
274
280
end
275
281
else
276
282
proc do |output |
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module TestIRB
8
8
class InputMethodTest < TestCase
9
9
def setup
10
10
@conf_backup = IRB . conf . dup
11
+ IRB . init_config ( nil )
11
12
IRB . conf [ :LC_MESSAGES ] = IRB ::Locale . new
12
13
save_encodings
13
14
end
@@ -33,6 +34,21 @@ def test_initialization
33
34
assert_not_nil Reline . dig_perfect_match_proc
34
35
end
35
36
37
+ def test_colorize
38
+ original_colorable = IRB ::Color . method ( :colorable? )
39
+ IRB ::Color . instance_eval { undef :colorable? }
40
+ IRB ::Color . define_singleton_method ( :colorable? ) { true }
41
+ workspace = IRB ::WorkSpace . new ( binding )
42
+ input_method = IRB ::RelineInputMethod . new ( IRB ::RegexpCompletor . new )
43
+ IRB . conf [ :MAIN_CONTEXT ] = IRB ::Irb . new ( workspace , input_method ) . context
44
+ assert_equal "\e [1m$\e [0m\e [m" , Reline . output_modifier_proc . call ( '$' , complete : false )
45
+ assert_equal "\e [1m$\e [0m\e [m \e [34m\e [1m1\e [0m + \e [34m\e [1m2\e [0m" , Reline . output_modifier_proc . call ( '$ 1 + 2' , complete : false )
46
+ assert_equal "\e [32m\e [1m$a\e [0m" , Reline . output_modifier_proc . call ( '$a' , complete : false )
47
+ ensure
48
+ IRB ::Color . instance_eval { undef :colorable? }
49
+ IRB ::Color . define_singleton_method ( :colorable? , original_colorable )
50
+ end
51
+
36
52
def test_initialization_without_use_autocomplete
37
53
original_show_doc_proc = Reline . dialog_proc ( :show_doc ) &.dialog_proc
38
54
empty_proc = Proc . new { }
You can’t perform that action at this time.
0 commit comments