Class: Charming::Presentation::UI::BorderPainter

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/ui/border_painter.rb

Constant Summary collapse

DEFAULT_SIDES =
%i[top right bottom left].freeze

Instance Method Summary collapse

Constructor Details

#initialize(border:, sides: nil, foreground: nil, background: nil) ⇒ BorderPainter

Returns a new instance of BorderPainter.



9
10
11
12
13
14
# File 'lib/charming/presentation/ui/border_painter.rb', line 9

def initialize(border:, sides: nil, foreground: nil, background: nil)
  @border = border
  @sides = Array(sides || DEFAULT_SIDES).map(&:to_sym)
  @foreground = foreground
  @background = background
end

Instance Method Details

#paint(lines, inner_width) ⇒ Object



16
17
18
19
20
21
# File 'lib/charming/presentation/ui/border_painter.rb', line 16

def paint(lines, inner_width)
  horizontal = @border.horizontal * inner_width
  body = lines.map { |line| border_line(line, inner_width) }

  [top_border(horizontal), *body, bottom_border(horizontal)].compact
end