mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Do not colorize partially-correct inspect
This is to prevent a yellow-mixed output for ActiveSupport::TimeWithZone.
Follows up https://github.com/ruby/irb/pull/159 and https://github.com/ruby/ruby/pull/3967.
a5804c3560
This commit is contained in:
parent
9b7ceb6765
commit
f30a3a0629
1 changed files with 9 additions and 1 deletions
|
@ -71,6 +71,9 @@ module IRB # :nodoc:
|
||||||
end
|
end
|
||||||
private_constant :TOKEN_SEQ_EXPRS
|
private_constant :TOKEN_SEQ_EXPRS
|
||||||
|
|
||||||
|
ERROR_TOKENS = TOKEN_SEQ_EXPRS.keys.select { |k| k.to_s.end_with?('error') }
|
||||||
|
private_constant :ERROR_TOKENS
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def colorable?
|
def colorable?
|
||||||
$stdout.tty? && supported? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
|
$stdout.tty? && supported? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
|
||||||
|
@ -119,6 +122,11 @@ module IRB # :nodoc:
|
||||||
length = 0
|
length = 0
|
||||||
|
|
||||||
scan(code, allow_last_error: !complete) do |token, str, expr|
|
scan(code, allow_last_error: !complete) do |token, str, expr|
|
||||||
|
# IRB::ColorPrinter skips colorizing fragments with any invalid token
|
||||||
|
if ignore_error && ERROR_TOKENS.include?(token)
|
||||||
|
return Reline::Unicode.escape_for_print(code)
|
||||||
|
end
|
||||||
|
|
||||||
in_symbol = symbol_state.scan_token(token)
|
in_symbol = symbol_state.scan_token(token)
|
||||||
str.each_line do |line|
|
str.each_line do |line|
|
||||||
line = Reline::Unicode.escape_for_print(line)
|
line = Reline::Unicode.escape_for_print(line)
|
||||||
|
@ -188,7 +196,7 @@ module IRB # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch_seq(token, expr, str, in_symbol:, ignore_error:)
|
def dispatch_seq(token, expr, str, in_symbol:, ignore_error:)
|
||||||
if token == :on_parse_error or token == :compile_error
|
if ERROR_TOKENS.include?(token)
|
||||||
ignore_error ? nil : TOKEN_SEQ_EXPRS[token][0]
|
ignore_error ? nil : TOKEN_SEQ_EXPRS[token][0]
|
||||||
elsif in_symbol
|
elsif in_symbol
|
||||||
[YELLOW]
|
[YELLOW]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue