Unicode box drawing characters, and functions that assemble them into lines, boxes and borders.
A line type selects a character set: :light, :heavy and :double have
their own sets, and :rounded is available through get_chars/1 and
border_style_chars/1. Any other line type falls back to :light.
Each set is a map keyed by :horizontal, :vertical, :top_left,
:top_right, :bottom_left, :bottom_right, :cross, :tee_up,
:tee_down, :tee_left and :tee_right.
iex> Drafter.Draw.BoxDrawing.draw_box(3, 3, :heavy)
["┏━┓", "┃ ┃", "┗━┛"]
Summary
Functions
The character set for a border style.
The character to draw where char2 is written over char1.
A box drawn around content_lines with title centred on the top edge.
An empty box width columns wide and height rows tall, one string per row.
A box drawn around content_lines, one string per row.
One character from a line type's set, named by char_type.
The character set for a line type.
A string of width horizontal line characters in style, which defaults to :light.
A list of height vertical line characters in style, one per row.
Types
Functions
@spec border_style_chars(border_style()) :: map()
The character set for a border style.
:none gives an empty map; :solid, :rounded, :thick and :double give
the :light, :rounded, :heavy and :double line-type sets. Any other value
raises FunctionClauseError.
Examples
iex> Drafter.Draw.BoxDrawing.border_style_chars(:none)
%{}
iex> Drafter.Draw.BoxDrawing.border_style_chars(:rounded).top_left
"╭"
iex> Drafter.Draw.BoxDrawing.border_style_chars(:thick).vertical
"┃"
The character to draw where char2 is written over char1.
A space on either side yields the other character, and two equal characters
yield that character. Any other pair yields char2; no junction character is
derived from the two line segments.
Examples
iex> Drafter.Draw.BoxDrawing.combine_chars(" ", "│")
"│"
iex> Drafter.Draw.BoxDrawing.combine_chars("─", " ")
"─"
iex> Drafter.Draw.BoxDrawing.combine_chars("─", "│")
"│"
@spec draw_border_with_title([String.t()], String.t(), border_style()) :: [String.t()]
A box drawn around content_lines with title centred on the top edge.
The box is as wide as the longer of the longest content line and title plus
two, so a title always has a line character on either side. An odd remainder puts
the extra line character on the right of the title. A :none border style returns
content_lines unchanged and ignores title. An empty content_lines gives one
blank interior row.
Examples
iex> Drafter.Draw.BoxDrawing.draw_border_with_title(["ab"], "T", :solid)
["┌─T─┐", "│ab │", "└───┘"]
iex> Drafter.Draw.BoxDrawing.draw_border_with_title(["abcdef"], "T", :solid)
["┌──T───┐", "│abcdef│", "└──────┘"]
iex> Drafter.Draw.BoxDrawing.draw_border_with_title(["ab"], "T", :none)
["ab"]
@spec draw_box(non_neg_integer(), non_neg_integer(), line_type() | :rounded) :: [ String.t() ]
An empty box width columns wide and height rows tall, one string per row.
The interior is filled with spaces. style defaults to :light. width and
height must both be at least 2; a smaller value raises FunctionClauseError.
Examples
iex> Drafter.Draw.BoxDrawing.draw_box(4, 3)
["┌──┐", "│ │", "└──┘"]
iex> Drafter.Draw.BoxDrawing.draw_box(2, 2, :rounded)
["╭╮", "╰╯"]
A box drawn around content_lines, one string per row.
The box is as wide as the longest line, which is measured with
String.length/1 and so counts double-width characters as one column. Shorter
lines are padded on the right. An empty list gives a 2x2 empty box. style
defaults to :light.
Examples
iex> Drafter.Draw.BoxDrawing.draw_box_with_content(["hi", "there"])
["┌─────┐", "│hi │", "│there│", "└─────┘"]
iex> Drafter.Draw.BoxDrawing.draw_box_with_content([])
["┌┐", "└┘"]
One character from a line type's set, named by char_type.
Returns a single space when the set has no such key.
Examples
iex> Drafter.Draw.BoxDrawing.get_char(:heavy, :vertical)
"┃"
iex> Drafter.Draw.BoxDrawing.get_char(:light, :diagonal)
" "
The character set for a line type.
Returns the :light set for any line type that has no set of its own, which is
the case for :dotted and :dashed.
Examples
iex> Drafter.Draw.BoxDrawing.get_chars(:double).cross
"╬"
iex> Drafter.Draw.BoxDrawing.get_chars(:dotted).top_left
"┌"
@spec horizontal_line(non_neg_integer(), line_type() | :rounded) :: String.t()
A string of width horizontal line characters in style, which defaults to :light.
Examples
iex> Drafter.Draw.BoxDrawing.horizontal_line(4)
"────"
iex> Drafter.Draw.BoxDrawing.horizontal_line(4, :double)
"════"
@spec vertical_line(non_neg_integer(), line_type() | :rounded) :: [String.t()]
A list of height vertical line characters in style, one per row.
style defaults to :light.
Examples
iex> Drafter.Draw.BoxDrawing.vertical_line(2, :heavy)
["┃", "┃"]