1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/irb/color_printer.rb

22 lines
474 B
Ruby

# frozen_string_literal: true
require 'pp'
module IRB
class ColorPrinter < ::PP
def self.pp(obj, out = $>, width = 79)
q = ColorPrinter.new(out, width)
q.guard_inspect_key {q.pp obj}
q.flush
out
end
def text(str, width = str.length)
case str
when /\A#</, '=', '>'
super(Color.colorize(str, [:GREEN]), width)
else
super(Color.colorize_code(str, ignore_error: true), width)
end
end
end
end