mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
98bd7e87a0
The incompatible interface is not helpful, again if you want to use it as a standalone library, falling it back to PP. Original PP.pp also ends with `out << "\n"`. https://github.com/ruby/irb/commit/4c74c7d84c
28 lines
590 B
Ruby
28 lines
590 B
Ruby
# 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
|