ex_prompt v0.1.1 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
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
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))
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?”)
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? “)
Same as string/1
but it will continue to “prompt” the user in case of an empty response.