Class: Helium::Console::ColorPrinter

Inherits:
Pry::ColorPrinter
  • Object
show all
Defined in:
lib/helium/console/printer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pp(obj, output = $DEFAULT_OUTPUT, max_width = 79) ⇒ Object



6
7
8
9
10
11
# File 'lib/helium/console/printer.rb', line 6

def self.pp(obj, output = $DEFAULT_OUTPUT, max_width = 79)
  queue = ColorPrinter.new(output, max_width, "\n")
  queue.guard_inspect_key { queue.pp(obj) }
  queue.flush
  output << "\n"
end

Instance Method Details

#length_of(str) ⇒ Object



29
30
31
# File 'lib/helium/console/printer.rb', line 29

def length_of(str)
  ColorizedString.new(str).uncolorize.length
end

#multiline?(formatted) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/helium/console/printer.rb', line 23

def multiline?(formatted)
  result = formatted.is_a?(Formatter::LazyStringEvaluator)
  result ||= formatted.lines.count > 1
  result || length_of(formatted.chomp) >= maxwidth - 2
end

#pp(object) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/helium/console/printer.rb', line 13

def pp(object)
  formatted = Helium::Console.format(object, max_width: maxwidth)
  output << "\n" if multiline?(formatted)

  formatted.lines.each.with_index do |line, index|
    output << "\n" unless index.zero?
    output << line.chomp
  end
end