diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2020-12-28 22:16:08 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2020-12-28 23:01:00 -0800 |
commit | c715fb46c2d8eab48323a6008c5dbca550ebe2e0 (patch) | |
tree | 0f3edfd82629a620f08dd4e05f4f979f13648275 /lib/irb/color_printer.rb | |
parent | 1ffb267c5c782ea15d01beb90d031274ca88cd8e (diff) |
[ruby/irb] Enhance colored inspect output
https://github.com/ruby/irb/commit/dffcdb5269
Diffstat (limited to 'lib/irb/color_printer.rb')
-rw-r--r-- | lib/irb/color_printer.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/irb/color_printer.rb b/lib/irb/color_printer.rb new file mode 100644 index 0000000000..187c337187 --- /dev/null +++ b/lib/irb/color_printer.rb @@ -0,0 +1,22 @@ +# 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 |