Class: Prompts::Box
Constant Summary
collapse
- SOLID_BORDER =
{top_left: "┌", top_right: "┐", bottom_left: "└", bottom_right: "┘", horizontal: "─", vertical: "│"}.freeze
- DOUBLE_BORDER =
{top_left: "╔", top_right: "╗", bottom_left: "╚", bottom_right: "╝", horizontal: "═", vertical: "║"}.freeze
- HEAVY_BORDER =
{top_left: "┏", top_right: "┓", bottom_left: "┗", bottom_right: "┛", horizontal: "━", vertical: "┃"}.freeze
- ROUNDED_BORDER =
{top_left: "╭", top_right: "╮", bottom_left: "╰", bottom_right: "╯", horizontal: "─", vertical: "│"}.freeze
Constants included
from TextUtils
TextUtils::ANSI_REGEX
Instance Method Summary
collapse
Methods included from TextUtils
#format_line, #strip_ansi, #wrap_text
Constructor Details
#initialize(width: MAX_WIDTH, padded: false, border_color: nil, border_style: :rounded) ⇒ Box
Returns a new instance of Box.
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/prompts/box.rb', line 12
def initialize(width: MAX_WIDTH, padded: false, border_color: nil, border_style: :rounded)
@width = width
@padded = padded
@border_color = border_color
@line_padding = SPACE * 1
@border_parts = case border_style
when :solid then SOLID_BORDER
when :double then DOUBLE_BORDER
when :heavy then HEAVY_BORDER
else ROUNDED_BORDER
end
@content = []
end
|
Instance Method Details
#centered(text) ⇒ Object
26
27
28
|
# File 'lib/prompts/box.rb', line 26
def centered(text)
@content.concat align(text, :center)
end
|
#gap ⇒ Object
38
39
40
|
# File 'lib/prompts/box.rb', line 38
def gap
@content.concat align(EMPTY, :center)
end
|
#left(text) ⇒ Object
30
31
32
|
# File 'lib/prompts/box.rb', line 30
def left(text)
@content.concat align(text, :left)
end
|
#lines ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/prompts/box.rb', line 42
def lines
[].tap do |output|
output << top_border
align(EMPTY, :center).each { |line| output << @line_padding + line } if @padded
@content.each do |line|
output << @line_padding + line
end
align(EMPTY, :center).each { |line| output << @line_padding + line } if @padded
output << bottom_border
end
end
|
#right(text) ⇒ Object
34
35
36
|
# File 'lib/prompts/box.rb', line 34
def right(text)
@content.concat align(text, :right)
end
|