TermUI.Widgets.Toast (TermUI v1.0.0)

View Source

Toast notification widget for brief messages with caller-driven expiration.

Toasts appear at the screen edge and carry an expiration duration. A caller must periodically call ToastManager.tick/1 (normally from a root Command.interval/2 message) to remove expired toasts. Multiple toasts stack vertically. Toasts don't capture focus or block interaction.

Usage

Toast.new(
  message: "File saved successfully",
  type: :success,
  duration: 3000,
  position: :bottom_right
)

Toast Types

  • :info - Information (blue)
  • :success - Success (green)
  • :warning - Warning (yellow)
  • :error - Error (red)

Positions

  • :top_left, :top_center, :top_right
  • :bottom_left, :bottom_center, :bottom_right

Summary

Functions

Dismisses the toast.

Gets the elapsed time since toast was created.

Gets the toast position.

Gets the toast type.

Creates new Toast widget props.

Checks if toast should auto-dismiss based on elapsed time.

Gets whether the toast is visible.

Functions

dismiss_toast(state)

@spec dismiss_toast(map()) :: map()

Dismisses the toast.

elapsed_time(state)

@spec elapsed_time(map()) :: non_neg_integer()

Gets the elapsed time since toast was created.

get_position(state)

@spec get_position(map()) :: atom()

Gets the toast position.

get_type(state)

@spec get_type(map()) :: atom()

Gets the toast type.

new(opts)

@spec new(keyword()) :: map()

Creates new Toast widget props.

Options

  • :message - Toast message (required)
  • :type - Toast type: :info, :success, :warning, :error (default: :info)
  • :duration - Auto-dismiss duration in ms (default: 3000, nil for no auto-dismiss)
  • :position - Screen position (default: :bottom_right)
  • :width - Toast width (default: 40)
  • :on_dismiss - Callback when toast is dismissed
  • :style - Style for toast background
  • :icon_style - Style for icon
  • :message_style - Style for message text

should_dismiss?(state)

@spec should_dismiss?(map()) :: boolean()

Checks if toast should auto-dismiss based on elapsed time.

visible?(state)

@spec visible?(map()) :: boolean()

Gets whether the toast is visible.