ex_prompt v0.1.5 ExPrompt View Source

ExPrompt is a helper package to add interactivity to your command line applications as easy as possible.

It allows common operations such as:

  • Asking for an answer.
  • Asking for a "required" answer.
  • Choosing between several options.
  • Asking for confirmation.
  • Asking for a password.

Link to this section Summary

Functions

Asks the user to select form a list of choices. It returns either the index of the element in the list or -1 if it's not found

Asks for confirmation to the user. It allows the user to answer or respond with the following options:

  • Yes, yes, YES, Y, y
  • No, no, NO, N, n

Alias for string/1

Asks for a password

Reads a line from :stdio displaying the prompt that is passed in

Same as string/1 but it will continue to "prompt" the user in case of an empty response

Link to this section Types

Link to this section Functions

Link to this function

choose(prompt, choices) View Source
choose(prompt(), choices()) :: integer()

Asks the user to select form a list of choices. It returns either the index of the element in the list or -1 if it's not found.

This method tries first to get said element by the list number, if it fails it will attempt to get the index from the list of choices by the value that the user wrote.

Examples

ExPrompt.choose("Favorite color?" , ~w(red green blue))

Link to this function

confirm(prompt) View Source
confirm(prompt()) :: boolean()

Asks for confirmation to the user. It allows the user to answer or respond with the following options:

  • Yes, yes, YES, Y, y
  • No, no, NO, N, n

In case that the answer is none of the above, it will prompt again until we do.

Examples

To ask whether the user wants to delete a file or not:

ExPrompt.confirm("Are you sure you want to delete this file?")

Alias for string/1.

Link to this function

get_required(prompt) View Source
get_required(prompt()) :: String.t()

Alias for string_required/1.

Link to this function

password(prompt, hide \\ true) View Source
password(prompt(), hide :: boolean()) :: String.t()

Asks for a password.

This method will hide the password by default as the user types. If that's not the desired behavior, it accepts false, and the password will be shown as it's being typed.

Examples

ExPrompt.password("Password: ")

ExPrompt.password("Password: ", false)

Reads a line from :stdio displaying the prompt that is passed in.

In case of any errors or :eof this function will return and empty string.

Examples

To ask a user for their name and await for the input:

ExPrompt.string("What is your name? ")

Link to this function

string_required(prompt) View Source
string_required(prompt()) :: String.t()

Same as string/1 but it will continue to "prompt" the user in case of an empty response.

Alias for confirm/1.