View Source Owl.Box (Owl v0.4.0)

Allows wrapping data to boxes.

Link to this section Summary

Functions

Wraps data into a box.

Link to this section Functions

@spec new(Owl.Data.t(),
  padding: non_neg_integer(),
  padding_x: non_neg_integer(),
  padding_y: non_neg_integer(),
  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 | :solid_rounded | :double | :none,
  title: nil | Owl.Data.t()
) :: Owl.Data.t()

Wraps data into a box.

options

Options

  • :padding - sets the padding area for all four sides at once. Defaults to 0.
  • :padding_x - sets :padding_right and :padding_left at once. Overrides value set by :padding. Defaults to 0.
  • :padding_y - sets :padding_top and :padding_bottom at once. Overrides value set by :padding. Defaults to 0.
  • :padding_top - sets the padding area for top side. Overrides value set by :padding_y or :padding. Defaults to 0.
  • :padding_bottom - sets the padding area for bottom side. Overrides value set by :padding_y or :padding. Defaults to 0.
  • :padding_right - sets the padding area for right side. Overrides value set by :padding_x or :padding. Defaults to 0.
  • :padding_left - sets the padding area for left side. Overrides value set by :padding_x or :padding. Defaults to 0.
  • :min_height - sets the minimum height of the box, including paddings and size of the borders. Defaults to 0.
  • :min_width - sets the minimum width of the box, including paddings and size of the borders. Defaults to 0.
  • :max_width - sets the maximum width of the box, including paddings and size of the borders. Defaults to width of the terminal, if available, :infinity otherwise.
  • :horizontal_align - sets the horizontal alignment of the content inside a box. Defaults to :right.
  • :vertical_align - sets the vertical alignment of the content inside a box. Defaults to :top.
  • :border_style - sets the border style. Defaults to :solid.
  • :title - sets a title that is displayed in a top border. Ignored if :border_style is :none. Defaults to nil.

examples

Examples

iex> "Owl" |> Owl.Box.new() |> to_string()
"""
┌───┐
│Owl│
└───┘
""" |> String.trim_trailing()

iex> "Owl" |> Owl.Box.new(padding_x: 4) |> 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.Data.tag(:green)
...> |> Owl.Box.new(title: Owl.Data.tag("Red!", :red))
...> |> Owl.Data.tag(:cyan)
...> |> Owl.Data.to_ansidata()
...> |> to_string()
"""
┌─Red!────┐
│Green!   │
└─────────┘
""" |> String.trim_trailing()