Alaja.Components.Box (Alaja v2.0.0)

Copy Markdown View Source

Static box/container with borders for terminal output.

Renders a bordered box around content, with optional title.

Usage

iex> Alaja.Components.Box.print("Hello, world!", title: "Greeting")
# ╭─ Greeting ──────╮
# │ Hello, world!   │
# ╰─────────────────╯

As a wrapper (post-processor)

As of v0.3.0, render/2 accepts a String.t(), [String.t()], OR an Alaja.Buffer.t() as its content. When passed a Buffer, the box wraps it at the buffer's exact width — this is the foundation for composing components inside boxes. The result is always a Buffer (Buffer-in, Buffer-out).

Cell engine

render/2 returns an Alaja.Buffer.t/0. The width is determined by the content's width plus padding. If the content is a Buffer, width is taken from buffer.width + padding * 2.

Summary

Functions

Prints a box around the given content.

Renders a box around content and returns an Alaja.Buffer.t/0.

Types

content()

@type content() :: String.t() | [String.t()] | Alaja.Buffer.t()

Functions

print(content, opts \\ [])

@spec print(
  content(),
  keyword()
) :: :ok

Prints a box around the given content.

render(content, opts \\ [])

@spec render(
  content(),
  keyword()
) :: Alaja.Buffer.t()

Renders a box around content and returns an Alaja.Buffer.t/0.

Options

  • :title - Optional title in the top border
  • :border - Border style (default :rounded)
  • :border_color - RGB tuple for border color (default cyan)
  • :width - Inner content width (default: auto from content)
  • :padding - Inner horizontal padding (default 1)