Module: Chamomile::Place
- Defined in:
- lib/chamomile/styling/place.rb
Class Method Summary collapse
- .place(width, height, h_pos, v_pos, str) ⇒ Object
- .place_horizontal(width, pos, str) ⇒ Object
- .place_vertical(height, pos, str) ⇒ Object
Class Method Details
.place(width, height, h_pos, v_pos, str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/chamomile/styling/place.rb', line 6 def place(width, height, h_pos, v_pos, str) lines = str.split("\n", -1) # Horizontal placement lines = Align.horizontal(lines, width, h_pos) # Vertical placement lines = Align.vertical(lines, height, v_pos) # Ensure all lines are padded to full width lines.map do |line| line_width = ANSI.printable_width(line) pad = width - line_width pad.positive? ? "#{line}#{" " * pad}" : line end.join("\n") end |
.place_horizontal(width, pos, str) ⇒ Object
23 24 25 26 |
# File 'lib/chamomile/styling/place.rb', line 23 def place_horizontal(width, pos, str) lines = str.split("\n", -1) Align.horizontal(lines, width, pos).join("\n") end |