Module: Chamomile::Place

Defined in:
lib/chamomile/styling/place.rb

Class Method Summary collapse

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

.place_vertical(height, pos, str) ⇒ Object



28
29
30
31
# File 'lib/chamomile/styling/place.rb', line 28

def place_vertical(height, pos, str)
  lines = str.split("\n", -1)
  Align.vertical(lines, height, pos).join("\n")
end