Class: Charming::UI::BorderPainter
- Inherits:
-
Object
- Object
- Charming::UI::BorderPainter
- Defined in:
- lib/charming/presentation/ui/border_painter.rb
Overview
BorderPainter draws a Border's glyphs around content lines, optionally
coloring the border. foreground is a single color or a per-side hash
({top:, right:, bottom:, left:}); corners take the top/bottom row's
color. background colors border cells; when it merely inherits the box
background (background_explicit: false) it only paints alongside a
foreground, preserving unstyled borders on unstyled boxes.
Constant Summary collapse
- DEFAULT_SIDES =
%i[top right bottom left].freeze
Instance Method Summary collapse
-
#initialize(border:, sides: nil, foreground: nil, background: nil, background_explicit: false) ⇒ BorderPainter
constructor
A new instance of BorderPainter.
- #paint(lines, inner_width) ⇒ Object
Constructor Details
#initialize(border:, sides: nil, foreground: nil, background: nil, background_explicit: false) ⇒ BorderPainter
Returns a new instance of BorderPainter.
14 15 16 17 18 19 20 |
# File 'lib/charming/presentation/ui/border_painter.rb', line 14 def initialize(border:, sides: nil, foreground: nil, background: nil, background_explicit: false) @border = border @sides = Array(sides || DEFAULT_SIDES).map(&:to_sym) @foreground = foreground @background = background @background_explicit = background_explicit end |
Instance Method Details
#paint(lines, inner_width) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/charming/presentation/ui/border_painter.rb', line 22 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 |