Alaja.Printer.Interactive (Alaja v1.0.0)

Copy Markdown View Source

Interactive user-input functions for terminal CLI applications.

Provides prompts for questions, yes/no confirmation, predefined-option selection, and bullet-list menus.

Usage

answer = Alaja.Printer.Interactive.question("What's your name?")
:yes  = Alaja.Printer.Interactive.yesno("Continue?")
Alaja.Printer.Interactive.menu("Select option:", [{"A", :a}, {"B", :b}])

Summary

Functions

Asks a question to the user and returns their answer.

Question with predefined options.

Yes or no question.

Functions

question(text, opts \\ [])

@spec question(
  String.t(),
  keyword()
) :: String.t()

Asks a question to the user and returns their answer.

Options

  • :color - Text color (default: :white)
  • :align - Text alignment (default: :left)

Examples

iex> question("What is your name?")
"John"

iex> question("Enter value:", color: :cyan)
"42"

question_with_options(text, options, opts \\ [])

@spec question_with_options(String.t(), list(), keyword()) :: any() | :error

Question with predefined options.

Returns the value associated with the selected option, or :error if the answer doesn't match any option.

Examples

iex> question_with_options("Choose:", [{"Yes", :yes}, {"No", :no}])
:yes

yesno(text, opts \\ [])

@spec yesno(
  String.t(),
  keyword()
) :: :yes | :no

Yes or no question.

Returns :yes or :no.

Options

  • :default - Default answer if user presses Enter (default: :no)

Examples

iex> yesno("Do you want to continue?")
:yes

iex> yesno("Are you sure?", default: :yes)
:no