Class: IRB::ColorPrinter
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.pp(obj, out = $>, width = screen_width) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/irb/color_printer.rb', line 8 def pp(obj, out = $>, width = screen_width) q = ColorPrinter.new(out, width) q.guard_inspect_key {q.pp obj} q.flush out << "\n" end |
Instance Method Details
#pp(obj) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/irb/color_printer.rb', line 24 def pp(obj) if obj.is_a?(String) # Avoid calling Ruby 2.4+ String#pretty_print that splits a string by "\n" text(obj.inspect) else super end end |
#text(str, width = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/irb/color_printer.rb', line 33 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 |