Alaja.Structures.MessageInfo (Alaja v1.0.0)

Copy Markdown View Source

Contains all information related to message printing.

Fields

  • chunks: List of ChunkText to print
  • align: Alignment (:left, :center, :right, :justified)
  • padding: Padding (integer or tuple {top, right, bottom, left})
  • add_line: Additional lines (:before, :after, :both, :none)
  • raw_coords: Coordinates for raw mode {x, y}

Examples

iex> MessageInfo.new([ChunkText.new("Hello")])
%MessageInfo{chunks: [...], align: :left, padding: 0, ...}

iex> MessageInfo.new([ChunkText.new("Hello")], align: :center, padding: 2)
%MessageInfo{chunks: [...], align: :center, padding: 2, ...}

Summary

Functions

Gets the complete message text (without formatting).

Gets the message width (text length without formatting).

Creates a new MessageInfo structure.

Normalizes padding to tuple {top, right, bottom, left}.

Types

add_line()

@type add_line() :: :before | :after | :both | :none

align()

@type align() :: :left | :center | :right | :justified

padding()

@type padding() :: integer() | {integer(), integer(), integer(), integer()}

t()

@type t() :: %Alaja.Structures.MessageInfo{
  add_line: add_line(),
  align: align(),
  chunks: [Alaja.Structures.ChunkText.t()],
  padding: padding(),
  raw_coords: {integer(), integer()} | nil
}

Functions

get_text(message_info)

@spec get_text(t()) :: String.t()

Gets the complete message text (without formatting).

Examples

iex> msg = MessageInfo.new(["Hello", " world"])
iex> MessageInfo.get_text(msg)
"Hello world"

get_width(message_info)

@spec get_width(t()) :: integer()

Gets the message width (text length without formatting).

Examples

iex> msg = MessageInfo.new(["Hello world"])
iex> MessageInfo.get_width(msg)
11

new(chunks, opts \\ [])

@spec new(
  [String.t() | Alaja.Structures.ChunkText.t()],
  keyword()
) :: t()

Creates a new MessageInfo structure.

Parameters

  • chunks - List of ChunkText or strings (automatically converted)
  • opts - Options:
    • :align - Alignment (default: :left)
    • :padding - Padding (default: 0)
    • :add_line - Additional lines (default: :none)
    • :raw_coords - Coordinates for raw mode (default: nil)

Examples

iex> MessageInfo.new(["Hello", " world"])
%MessageInfo{chunks: [...], align: :left}

iex> MessageInfo.new([ChunkText.new("Hello")], align: :center, padding: 2)
%MessageInfo{chunks: [...], align: :center, padding: 2}

normalize_padding(padding)

@spec normalize_padding(padding()) :: {integer(), integer(), integer(), integer()}

Normalizes padding to tuple {top, right, bottom, left}.

Examples

iex> MessageInfo.normalize_padding(2)
{2, 2, 2, 2}

iex> MessageInfo.normalize_padding({1, 2, 3, 4})
{1, 2, 3, 4}