Class: RubyJard::BoxDrawer
- Inherits:
-
Object
- Object
- RubyJard::BoxDrawer
- Defined in:
- lib/ruby_jard/box_drawer.rb
Overview
Drawer to draw a nice single-line box that maximize screen area
Each screen has 4 corners and clock-wise corresponding ID:
-
Top-left => 1
-
Top-right => 2
-
Bottom-right => 3
-
Bottom-left => 4
For each screen, add each point to a coordinator hash.
-
If a point is occupied by 1 screen, draw normal box corner symbol.
-
If a point is occupied by 2 screens, look up in a map, and draw corresponding intersection corner symbol.
-
If a point is occupied by 3 or more screens, it’s definitely a + symbol.
The corner list at each point (x, y) is unique. If 2 screens overlap a point with same corner ID, it means 2 screens overlap, and have same corner symbol.
Constant Summary collapse
- CORNERS =
[ TOP_LEFT = 1, TOP_RIGHT = 2, BOTTOM_RIGHT = 3, BOTTOM_LEFT = 4 ].freeze
- HORIZONTAL_LINE =
'─'
- VERTICAL_LINE =
'│'
- CROSS_CORNER =
'┼'
- NORMALS_CORNERS =
{ TOP_LEFT => '┌', TOP_RIGHT => '┐', BOTTOM_RIGHT => '┘', BOTTOM_LEFT => '└' }.freeze
- OVERLAPPED_CORNERS =
{ [TOP_LEFT, TOP_RIGHT] => '┬', [TOP_LEFT, BOTTOM_RIGHT] => '┼', [TOP_LEFT, BOTTOM_LEFT] => '├', [TOP_RIGHT, BOTTOM_RIGHT] => '┤', [TOP_RIGHT, BOTTOM_LEFT] => '┼', [BOTTOM_RIGHT, BOTTOM_LEFT] => '┴' }.freeze
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(output:, screens:, color_scheme:) ⇒ BoxDrawer
constructor
A new instance of BoxDrawer.
Constructor Details
#initialize(output:, screens:, color_scheme:) ⇒ BoxDrawer
Returns a new instance of BoxDrawer.
48 49 50 51 52 |
# File 'lib/ruby_jard/box_drawer.rb', line 48 def initialize(output:, screens:, color_scheme:) @output = output @screens = screens @color_decorator = RubyJard::Decorators::ColorDecorator.new(color_scheme) end |
Instance Method Details
#draw ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ruby_jard/box_drawer.rb', line 54 def draw draw_basic_lines corners = calculate_corners draw_corners(corners) draw_titles end |