Packages
prompt
0.6.1
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)
# Terminal UI Library for Elixir
* [Motivation](#motivation)
* [Installation](#installation)
* [Basic Usage](#basic-usage)
* [Display text on the screen](#display-text-on-the-screen)
* [Ask the user for input](#ask-the-user-for-input)
* [Ask the user for a password](#ask-the-user-for-a-password)
* [Ask the user for confirmation](#ask-the-user-for-confirmation)
* [Custom confirmation choices](#custom-confirmation-choices)
* [List of selections](#list-of-selections)
* [Tables](#tables)
* [Advanced Usage](#advanced-usage-with-subcommands)
* [Example Application](#example)
[](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fsilbermm%2Fprompt%2Fblob%2Fmain%2Fexample.livemd)
## Motivation
To create a really great development experience and API for Elixir developers that want to build commandline tools.
## Installation
Add `prompt` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:prompt, "~> 0.5"}
]
end
```
[Read the official documentation](https://hexdocs.pm/prompt/Prompt.html)
## Basic Usage
All of the following commands take a keyword list of options for things like text color and positioning.
### Display text on the screen
[Prompt.display/2](https://hexdocs.pm/prompt/Prompt.html#display/2)
```elixir
Prompt.display("Hello, world!")
```
### Ask the user for input
[Prompt.text/2](https://hexdocs.pm/prompt/Prompt.html#text/2)
Useful for prompting the user to enter freeform text
```elixir
Prompt.text("Enter info here")
```
Will display:
```bash
> Enter info here:
```
and wait for the user to enter text
### Ask the user for a password
[Prompt.password/2](https://hexdocs.pm/prompt/Prompt.html#password/2)
When you need to hide the input that the user types
```elixir
Prompt.password("Enter password")
```
### Ask the user for confirmation
[Prompt.confirm/2](https://hexdocs.pm/prompt/Prompt.html#confirm/2)
```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
[Prompt.choice/2](https://hexdocs.pm/prompt/Prompt.html#choice/2)
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
[Prompt.select/2](https://hexdocs.pm/prompt/Prompt.html#select/2)
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
### Tables
[Prompt.table/2](https://hexdocs.pm/prompt/Prompt.html#table/2)
To show a table of data
```elixir
Prompt.table([["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]])
```
Will display
```bash
> +-------+------+---------+----------+
| Hello | from | the | terminal |
| this | is | another | row |
+-------+------+---------+----------+
```
## Advanced Usage with Subcommands
To use the more advanced features, see the [official documentation](https://hexdocs.pm/prompt/Prompt.html#module-subcommands)
## Example
For a complete example, take a look at [Slim - a cherry-picking tool](https://github.com/silbermm/slim_pickens)