diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-29 22:03:47 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-29 22:09:54 +0900 |
commit | 5b64d7ac6e7cbf759b859428f125539e58bac0bd (patch) | |
tree | 5e0773f8d47d2cf50824a4f91fb1c21e7cd649a5 /lib | |
parent | 12644e8b0208b01f4f4cea550d161a86e6f25aa8 (diff) |
Colorize errors more
* lib/irb/color.rb (IRB::Color.colorize_code): colorize
`compile_error` part as same as `on_parse_error`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb/color.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/irb/color.rb b/lib/irb/color.rb index caa7f5032a..0dbb16b60b 100644 --- a/lib/irb/color.rb +++ b/lib/irb/color.rb @@ -108,25 +108,34 @@ module IRB # :nodoc: symbol_state = SymbolState.new colored = +'' length = 0 + pos = [1, 0] scan(code).each do |elem| token = elem.event str = elem.tok expr = elem.state in_symbol = symbol_state.scan_token(token) - if seq = dispatch_seq(token, expr, str, in_symbol: in_symbol) - Reline::Unicode.escape_for_print(str).each_line do |line| + next if ([elem.pos[0], elem.pos[1] + str.bytesize] <=> pos) <= 0 + str.each_line do |line| + if line.end_with?("\n") + pos[0] += 1 + pos[1] = 0 + else + pos[1] += line.bytesize + end + line = Reline::Unicode.escape_for_print(line) + if seq = dispatch_seq(token, expr, line, in_symbol: in_symbol) colored << seq.map { |s| "\e[#{s}m" }.join('') colored << line.sub(/\Z/, clear) + else + colored << line end - else - colored << Reline::Unicode.escape_for_print(str) end - length += str.length + length += str.bytesize end # give up colorizing incomplete Ripper tokens - return code if length != code.length + return code if length != code.bytesize colored end |