View Source Tux.Alert (Tux v0.4.0)

An alert is a struct which encodes the textual and formatting information which can be used to display stylized error messages.

Examples

Please be aware that the colored and embolden parts cannot be seen in this example, nonetheless an alert in its simplest version looks roughly something like this:

│ ERR: Command error

And with additional details:

│ ERR: Command error
│ This section has more details about the error.

Summary

Types

t()

The alert struct

Functions

Set or update a given alert field.

Return a blank alert struct

Types

field()

@type field() :: :tag | :color | :title | :message

t()

@type t() :: %Tux.Alert{
  color: fun(),
  message: String.t(),
  tag: String.t(),
  title: String.t()
}

The alert struct

value()

@type value() :: String.t() | fun()

Functions

add(alert, atom, tag)

@spec add(t(), field(), value()) :: t()

Set or update a given alert field.

Examples

iex> alias Tux.Alert
...>
...> Alert.new()
...> |> Alert.add(:tag, "ERR")
...> |> Alert.add(:color, &Tux.Colors.red/1)
...> |> Alert.add(:title, "Title")
...> |> Alert.add(:message, "Message")
%Tux.Alert{color: &Tux.Colors.red/1, message: "Message", tag: "ERR", title: "Title"}

new()

@spec new() :: t()

Return a blank alert struct

Examples

iex> Tux.Alert.new()
%Tux.Alert{tag: nil, color: nil, title: nil, message: nil}