Module: Bcome::Draw

Included in:
Ssh::ProxyHop, Tree
Defined in:
lib/objects/modules/draw.rb

Constant Summary collapse

BOTTOM_ANCHOR =

Tree shapes

'└───╸'
MID_SHIPS =
'├───╸'
BRANCH =
''
LEFT_PADDING =
"\s" * 6
INGRESS =
''
BLIP =
'▐▆'
BOX_SIDE =

# Box shapes

''
BOX_TOP_LEFT =
''
BOX_TOP_RIGHT =
''
BOX_BOTTOM_LEFT =
''
BOX_BOTTOM_RIGHT =
''
BOX_HORIZONTAL_LINE =
''

Instance Method Summary collapse

Instance Method Details

#box_it(array_of_lines, padding = 1, _box_colour = :bc_cyan) ⇒ Object

Takes an array of strings, each representing a line Draws a box around the lines, and returns a new array padding may be provided



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/objects/modules/draw.rb', line 26

def box_it(array_of_lines, padding = 1, _box_colour = :bc_cyan)
  max_length = max_box_line_length(array_of_lines)
  pad_string = "\s" * padding

  box_lines = [
    # Set the top box line
    "#{BOX_TOP_LEFT}#{BOX_HORIZONTAL_LINE * (max_length + (padding + 1))}#{BOX_TOP_RIGHT}"
  ]

  array_of_lines.each do |line|
    line_length = line.sanitize.length
    box_lines << "#{BOX_SIDE}#{pad_string}" + line.to_s + "#{"\s" * (max_length - line_length)}#{pad_string}#{BOX_SIDE}"
  end

  # Set the bottom box line
  box_lines << "#{BOX_BOTTOM_LEFT}#{BOX_HORIZONTAL_LINE * (max_length + (padding + 1))}#{BOX_BOTTOM_RIGHT}"
  box_lines
end

#max_box_line_length(array_of_lines) ⇒ Object



45
46
47
# File 'lib/objects/modules/draw.rb', line 45

def max_box_line_length(array_of_lines)
  array_of_lines.max_by { |string| string.sanitize.length }.sanitize.length
end