123456789_123456789_123456789_123456789_123456789_

Class: IRB::ColorPrinter

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PP
Instance Chain:
self, PP
Inherits: PP
Defined in: lib/irb/color_printer.rb

Class Method Summary

Instance Method Summary

Class Method Details

.pp(obj, out = $>, width = screen_width)

[ GitHub ]

  
# 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

.screen_width (private)

[ GitHub ]

  
# File 'lib/irb/color_printer.rb', line 17

def screen_width
  Reline.get_screen_size.last
rescue Errno::EINVAL # in `winsize': Invalid argument - <STDIN>
  79
end

Instance Method Details

#pp(obj)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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