File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
9
9
### Added
10
10
11
11
- Better handling for formatting files with errors.
12
+ - Colorize the output snippet using IRB.
12
13
13
14
## [ 1.0.0]
14
15
Original file line number Diff line number Diff line change @@ -236,16 +236,22 @@ def highlight_error(error, source)
236
236
if line_number == error . lineno
237
237
part1 = Color . red ( ">" )
238
238
part2 = Color . gray ( "%#{ digits } d |" % line_number )
239
- warn ( "#{ part1 } #{ part2 } #{ lines [ line_index ] } " )
239
+ warn ( "#{ part1 } #{ part2 } #{ colorize_line ( lines [ line_index ] ) } " )
240
240
241
241
part3 = Color . gray ( " %#{ digits } s |" % " " )
242
242
warn ( "#{ part3 } #{ " " * error . column } #{ Color . red ( "^" ) } " )
243
243
else
244
244
prefix = Color . gray ( " %#{ digits } d |" % line_number )
245
- warn ( "#{ prefix } #{ lines [ line_index ] } " )
245
+ warn ( "#{ prefix } #{ colorize_line ( lines [ line_index ] ) } " )
246
246
end
247
247
end
248
248
end
249
+
250
+ # Take a line of Ruby source and colorize the output.
251
+ def colorize_line ( line )
252
+ require "irb"
253
+ IRB ::Color . colorize_code ( line , complete : false , ignore_error : true )
254
+ end
249
255
end
250
256
end
251
257
end
You can’t perform that action at this time.
0 commit comments