Packages
prompt
0.5.7
0.11.1-rc1
0.10.1
0.10.1-rc2
0.10.1-rc1
0.10.1-rc0
0.10.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.0
0.2.0
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
A terminal toolkit and a set of helpers for building console applications.
Current section
Files
Jump to
Current section
Files
README.md


[](https://hexdocs.pm/prompt/Prompt.html#content)
**STILL A WORK IN PROGRESS**
Easily build interactive CLI's in Elixir.
## Installation
Add `prompt` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:prompt, "~> 0.x.x"}
]
end
```
[Read the documentation](https://hexdocs.pm/prompt/Prompt.html)
## Basic Usage
### Ask the user for confirmation
```elixir
Prompt.confirm("Are you sure?")
```
Will display:
```bash
> Are you sure? (Y/n):
```
and will allow the user to just press [enter] to confirm
If you'd prefer `n` to be the default pass the `default_answer` option
```elixir
Prompt.confirm("Are you sure?", default_answer: :no)
```
Returns `:yes` or `:no` based on the answer
### Custom confirmation choices
Sometimes yes/no aren't the only choices a user can make, this method allows you to pass any choices as the confirmation.
```elixir
Prompt.choice("Accept, Reload or Cancel", accept: "a", reload: "r", cancel: "c")
```
displays
```bash
> Accept, Reload or Cancel (A/r/c):
```
Returns the key of the answer i.e `:accept`, `:reload` or `cancel` in this exammple
### List of selections
To show the user a list of options to select from
```elixir
Prompt.select("Choose a protocol", ["file://", "ssh://", "ftp://"])
```
Displays:
```bash
[1] file://
[2] ssh://
[3] ftp://
> Choose a protocol [1-3]:
```
and returns a string of their choice