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
Shows an options menu.
Asks a question to the user and returns their answer.
Question with predefined options.
Yes or no question.
Functions
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 predefined options.
The options list can take three shapes:
[{label, value}, ...]with string labels — the user types the label (or a prefix of it, case-insensitive).[{label, value}, ...]where value is an atom — the user can type the atom name (e.g.:llm→llm).- A 1-based index (
1,2,3) typed by the user.
Before reading the answer, the function lists the options under the
prompt so the user always knows what they can type. The :default
option chooses a pre-selected index that gets used if the user
just presses Enter.
Returns the value for the selected option, or :error if the
input does not match anything.
Examples
iex> question_with_options("Choose:", [{"Yes", :yes}, {"No", :no}])
:yes
iex> question_with_options("Continue?", [{"Y", :yes}, {"N", :no}], default: 1)
:yes
Yes or no question.
Returns :yes or :no.
Accepts y, yes, n, no, plus the index 1 for yes and 2
for no. The :default option (:yes or :no) is used when the
user just presses Enter.
Examples
iex> yesno("Do you want to continue?")
:yes
iex> yesno("Are you sure?", default: :yes)
:yes