diff options
Diffstat (limited to 'lib/irb/color_printer.rb')
-rw-r--r-- | lib/irb/color_printer.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb new file mode 100644 index 0000000000..73a150f881 --- /dev/null +++ b/lib/irb/color_printer.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true +require 'pp' +require 'irb/color' + +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 << "\n" + end + + def text(str, width = nil) + unless str.is_a?(String) + str = str.inspect + end + 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 |