chore(deps) updates
chore: Update documentation
Add link for zshcompletions
Use the issue tracker to report issues or feature requests.
Send patches to ~ahappydeath/prompt@lists.sr.ht
To create a really great development experience and API for Elixir developers that want to build commandline tools.
Add prompt
to your list of dependencies in mix.exs
:
def deps do
[
{:prompt, "~> 0.10.0"}
]
end
Read the official documentation
All of the following commands take a keyword list of options for things like text color and positioning.
Prompt.display("Hello, world!")
Prompt.text/2 Useful for prompting the user to enter freeform text
Prompt.text("Enter info here")
Will display:
> Enter info here:
and wait for the user to enter text
Prompt.password/2 When you need to hide the input that the user types
Prompt.password("Enter password")
Prompt.confirm("Are you sure?")
Will display:
> 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
Prompt.confirm("Are you sure?", default_answer: :no)
Returns :yes
or :no
based on the answer
Prompt.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.
Prompt.choice("Accept, Reload or Cancel", accept: "a", reload: "r", cancel: "c")
displays
> Accept, Reload or Cancel (A/r/c):
Returns the key of the answer i.e :accept
, :reload
or cancel
in this exammple
Prompt.select/2 To show the user a list of options to select from
Prompt.select("Choose a protocol", ["file://", "ssh://", "ftp://"])
Displays:
[1] file://
[2] ssh://
[3] ftp://
> Choose a protocol [1-3]:
and returns a string of their choice
Prompt.table/2 To show a table of data
Prompt.table([["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]])
Will display
> +-------+------+---------+----------+
| Hello | from | the | terminal |
| this | is | another | row |
+-------+------+---------+----------+
To use the more advanced features, see the official documentation
For a complete example, take a look at Genex - a password manager