Owl.Box (Owl v0.1.0) View Source
Allows wrapping data to boxes.
Link to this section Summary
Functions
Wraps data into a box.
Link to this section Types
Specs
opt() :: {:padding_top, non_neg_integer()} | {:padding_bottom, non_neg_integer()} | {:padding_right, non_neg_integer()} | {:padding_left, non_neg_integer()} | {:min_height, non_neg_integer()} | {:min_width, non_neg_integer()} | {:max_width, non_neg_integer() | :infinity} | {:horizontal_align, :left | :center | :right} | {:vertical_align, :top | :middle | :bottom} | {:border_style, :solid | :double | :none} | {:title, nil | Owl.Data.t()}
Link to this section Functions
Specs
new(Owl.Data.t(), [opt()]) :: Owl.Data.t()
Wraps data into a box.
Options are self-descriptive in definition of the type opt/0
, numbers mean number of symbols.
Examples
iex> "Owl" |> Owl.Box.new() |> to_string()
"""
┌───┐
│Owl│
└───┘
""" |> String.trim_trailing()
iex> "Hello\nworld!"
...> |> Owl.Box.new(
...> title: "Greeting!",
...> min_width: 20,
...> horizontal_align: :center,
...> border_style: :double
...> )
...> |> to_string()
"""
╔═Greeting!══════════╗
║ Hello ║
║ world! ║
╚════════════════════╝
""" |> String.trim_trailing()
iex> "Success"
...> |> Owl.Box.new(
...> min_width: 20,
...> min_height: 3,
...> border_style: :none,
...> horizontal_align: :right,
...> vertical_align: :bottom
...> )
...> |> to_string()
"""
Success
""" |> String.trim_trailing()
iex> "OK"
...> |> Owl.Box.new(min_height: 5, vertical_align: :middle)
...> |> to_string()
"""
┌──┐
│ │
│ │
│OK│
│ │
│ │
└──┘
""" |> String.trim_trailing()
iex> "VeryLongLine" |> Owl.Box.new(max_width: 6) |> to_string()
"""
┌────┐
│Very│
│Long│
│Line│
└────┘
""" |> String.trim_trailing()
iex> "VeryLongLine" |> Owl.Box.new(max_width: 4, border_style: :none) |> to_string()
"""
Very
Long
Line
""" |> String.trim_trailing()
iex> "Green!"
...> |> Owl.Tag.new(:green)
...> |> Owl.Box.new(title: Owl.Tag.new("Red!", :red))
...> |> Owl.Tag.new(:cyan)
...> |> Owl.Data.to_ansidata()
...> |> to_string()
"""
[36m┌─[31mRed![36m[49m────┐[39m[49m
[36m│[32mGreen![36m[49m │[39m[49m
[36m└─────────┘[39m[49m[0m
""" |> String.trim_trailing()