View Source Tux.Prompt (Tux v0.4.0)
Helper functions for retrieving user input as: strings, integers, floats or for asking for confirmations.
- Default values will be displayed between
[...]
at the end of the prompt. - Supports default values when no value (just enter) is typed.
Examples
alias Tux.Prompt
with true <- Prompt.for_confirmation("Really continue"),
{:ok, name} <- Prompt.for_string("What's your name", "Joe Doe"),
{:ok, age} <- Prompt.for_string("What's your age"),
{:ok, salary} <- Prompt.for_float("What's your salary") do
IO.puts("Name: #{name}, Age: #{age}, Salary: #{salary}")
end
Summary
Types
They type for the prompt message shown to the end user asking for a confirmation or some input.
Functions
Prompt and parse a yes
or no
answer
Prompt and parse a float answer
Prompt and parse an integer answer
Prompt and collect a string with the whitespace trimmed
Types
@type prompt() :: String.t()
They type for the prompt message shown to the end user asking for a confirmation or some input.
Functions
Prompt and parse a yes
or no
answer:
Tux.Prompt.for_confirmation("Really delete")
false
Tux.Prompt.for_confirmation("Really delete", :yes)
true
Prompt and parse a float answer:
Tux.Prompt.for_integer("What's your salary?")
{:ok, 25.0}
Tux.Prompt.for_integer("What's your salary?")
:error
Prompt and parse an integer answer:
Tux.Prompt.for_integer("What's your age?")
{:ok, 25}
Tux.Prompt.for_integer("What's your age?")
:error
Prompt and collect a string with the whitespace trimmed:
Tux.Prompt.for_integer("What's your name?")
{:ok, "Tux"}
Tux.Prompt.for_integer("What's your name?", "Joe Doe")
{:ok, "Joe Doe"}