Prompt (prompt v0.1.2) View Source

Build interactive command line interfaces.

  • confirm/1 prompt asks the user for a yes or no answer
  • select/2 prompt the user to choose one of several options
  • text/1 prompt for free form text
  • password/1 prompt for a password or other info that needs to be hidden

Link to this section Summary

Functions

Display a Y/n prompt.

Prompt the user for input, but conceal the users typing.

Displays options to the user denoted by numbers.

Display text on the screen and wait for the users text imput.

Link to this section Functions

Link to this function

confirm(question, opts \\ [])

View Source

Specs

confirm(String.t(), keyword()) :: :yes | :no | :error

Display a Y/n prompt.

Sets 'Y' as the the default answer, allowing the user to just press the enter key. To make 'n' the default answer pass the option default_answer: :no

Available options:

  • color: A color from the IO.ANSI module
  • default_answer: :yes or :no

Examples

iex> Prompt.confirm("Send the email?")
Send the email? (Y/n): Y
iex> :yes

iex> Prompt.confirm("Send the email?", default_answer: :no)
Send the email? (y/N): [enter]
iex> :no
Link to this function

password(display, opts \\ [])

View Source

Specs

password(String.t(), keyword()) :: String.t()

Prompt the user for input, but conceal the users typing.

Available options:

  • color: A color from the IO.ANSI module

Examples

iex> Prompt.password("Enter your passsword")
Enter your password: 
iex> "password"
Link to this function

select(display, choices, opts \\ [])

View Source

Specs

select(String.t(), [String.t()], keyword()) :: String.t() | :error

Displays options to the user denoted by numbers.

Available options:

  • color: A color from the IO.ANSI module

Examples

iex> Prompt.select("Choose One", ["Choice A", "Choice B"])
  [0] Choice A
  [1] Choice B
Choose One [0-1]: 1
iex> "Choice B"
Link to this function

text(display, opts \\ [])

View Source

Specs

text(String.t(), keyword()) :: String.t()

Display text on the screen and wait for the users text imput.

Available options:

  • color: A color from the IO.ANSI module

Examples

iex> Prompt.text("Enter your email")
Enter your email: t@t.com
iex> t@t.com