Prompt (prompt v0.5.7) View Source
Helpers for building interactive command line interfaces.
confirm/1
prompt asks the user for a yes or no answerchoice/2
prompt for asking the user to make a custom confirmation choiceselect/2
prompt the user to choose one of several optionstext/1
prompt for free form textpassword/1
prompt for a password or other info that needs to be hiddendisplay/1
displays text on the screen
Link to this section Summary
Functions
Display a choice prompt with custom answers. Takes a keyword list of answers in the form of atom to return and string to display.
Display a Y/n prompt.
Writes text to the screen.
Prompt the user for input, but conceal the users typing.
Displays options to the user denoted by numbers.
Print an ASCII table of data. Requires a list of lists as input.
Display text on the screen and wait for the users text imput.
Link to this section Functions
Specs
Display a choice prompt with custom answers. Takes a keyword list of answers in the form of atom to return and string to display.
[yes: "y", no: "n"]
will show "(y/n)" and return :yes
or :no
based on the choice.
Available options:
- default_answer: the default answer. If default isn't passed, the first is the default.
- color: A color from the
IO.ANSI
module
Examples
iex> Prompt.choice("Save password?", [yes: "y", no: "n", regenerate: "r"}, default_answer: :regenerate)
"Save Password? (y/n/R):" [enter]
iex> :regenerate
Specs
Display a Y/n prompt.
Sets 'Y' as the the default answer, allowing the user to just press the enter key. To make 'n' the default answer pass the option default_answer: :no
Available options:
- color: A color from the
IO.ANSI
module - default_answer: :yes or :no
Examples
iex> Prompt.confirm("Send the email?")
"Send the email? (Y/n):" Y
iex> :yes
iex> Prompt.confirm("Send the email?", default_answer: :no)
"Send the email? (y/N):" [enter]
iex> :no
Specs
Writes text to the screen.
Takes a single string argument or a list of strings where each item in the list will be diplayed on a new line.
Available options:
- color: A color from the
IO.ANSI
module - trim: true | false --- Defaults to false (will put a
at the end of the text
- position: :left | :right --- Print the content starting from the leftmost position or the rightmost position
- mask_line: true | false --- Prompts the user to press enter and afterwards masks the line just printed
- the main use case here is a password that you may want to show the user but hide after the user has a chance to write it down, or copy it.
Examples
iex> Prompt.display("Hello from the terminal!")
"Hello from the terminal!"
iex> Prompt.display(["Hello", "from", "the", "terminal"])
"Hello"
"from"
"the"
"terminal"
Specs
Prompt the user for input, but conceal the users typing.
Available options:
- color: A color from the
IO.ANSI
module
Examples
iex> Prompt.password("Enter your passsword")
"Enter your password:"
iex> "super_secret_passphrase"
Specs
Displays options to the user denoted by numbers.
Allows for a list of 2 tuples where the first value is what is displayed and the second value is what is returned to the caller.
Available options:
- color: A color from the
IO.ANSI
module
Examples
iex> Prompt.select("Choose One", ["Choice A", "Choice B"])
" [1] Choice A"
" [2] Choice B"
"Choose One [1-2]:" 1
iex> "Choice A"
iex> Prompt.select("Choose One", [{"Choice A", 1000}, {"Choice B", 1001}])
" [1] Choice A"
" [2] Choice B"
"Choose One [1-2]:" 2
iex> 1001
Specs
Print an ASCII table of data. Requires a list of lists as input.
Available Options
- header: true | false (default) --- use the first element as a header of the table
- TODO: title: "TITLE" --- Create a title for the table
- TODO: border: :normal
- TODO: borer_color:
Examples
iex> Prompt.table([["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]])
"
+-------+------+---------+----------+
| Hello | from | the | terminal |
| this | is | another | row |
+-------+------+---------+----------+
"
iex> Prompt.table([["One", "Two", "Three", "Four"], ["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]], header: true)
"
+-------+------+---------+----------+
| One | Two | Three | Four |
+-------+------+---------+----------+
| Hello | from | the | terminal |
| this | is | another | row |
+-------+------+---------+----------+
"
iex> Prompt.table([["Hello", "from", "the", "terminal!"],["this", "is", "another", "row"]], title: "MY TABLE")
"
+MY TABLE------+---------+----------+
| Hello | from | the | terminal |
| this | is | another | row |
+-------+------+---------+----------+
"
Specs
Display text on the screen and wait for the users text imput.
Available options:
- color: A color from the
IO.ANSI
module
Examples
iex> Prompt.text("Enter your email")
"Enter your email:" t@t.com
iex> t@t.com