Module: FancyIrb::SizeDetector

Extended by:
SizeDetector
Included in:
FancyIrb, SizeDetector
Defined in:
lib/fancy_irb/size_detector.rb

Instance Method Summary collapse

Instance Method Details

#height_of(data, width) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/fancy_irb/size_detector.rb', line 11

def height_of(data, width)
  data = data.to_s
  long_lines = data.split("\n").inject(0){ |sum, line|
    sum + width_of(line) / (width + 1)
  }
  data.count("\n") + long_lines
end

#width_of(data) ⇒ Object



5
6
7
8
9
# File 'lib/fancy_irb/size_detector.rb', line 5

def width_of(data)
  return 0 unless data
  data = Paint.unpaint data.to_s
  FancyIrb.unicode_display_width? ? Unicode::DisplayWidth.of(data) : data.length
end