Term::Prompt
Constants
Constructors
Instance methods
Ask a question.
Example:
prompt.ask("What is your name?")
Ask a question with autocomplete suggestions
Example:
frameworks = %w(Rails Django Flask Laravel Express React Vue Angular)
prompt.autocomplete("Choose a framework:", frameworks)
Gathers more than one answer
Example:
prompt.collect do
key(:name).ask("Name?")
key(:age).ask("Age?")
end
Ask for enhanced confirmation, especially for destructive operations
Example:
prompt.confirm("Delete all files?", destructive: true)
prompt.confirm("Deploy to production?", double_confirm: true)
Decorate the provided message using the given color. Color can be
a symbol, a Term::Color instance, or an {R, G, B} tuple.
Ask user to select a directory
Example:
prompt.directory_select("Choose a directory:")
Ask a question with indexed list
Example:
editors = %w(emacs nano vim)
prompt.enum_select("Select editor:", editors)
Expand available options
Example:
prompt = Term::Prompt.new
choices = [{
key: "Y",
name: "Overwrite",
value: :yes,
}, {
key: "n",
name: "Skip",
value: :no,
}]
prompt.expand("Overwrite shard.yml?", choices)
Ask user to select a file
Example:
prompt.file_select("Choose a file:")
# or with filters
prompt.file_select("Choose a Ruby file:", filter: [".rb", ".crystal"])
Ask a question with a keypress answer.
Example:
prompt.keypress("Press any key to continue")
# or
prompt.keypress("Press Ctrl+D to continue", keys: [:ctrl_d])
Ask a masked question. Masked questions replace each input character with a mask value.
Example:
prompt.mask("Please enter your password:")
Ask a question with multiple attributes activated
Example:
prompt.multi_select("What sizes?") do |menu|
menu.choice :large
menu.choices %w(:medium :small)
end
Ask a question with multiple attributes activated
Example:
choices = %w(Scorpion Jax Kitana Baraka Jade)
prompt.multi_select("Choose your destiny?", choices)
Ask a question with a multiline answer
Example:
prompt.multiline("Description?")
Ask a yes or no question, with "no" being the default answer.
Example:
prompt.no?("Would you like to continue?")
Ask user to select a file or directory
Example:
prompt.path_select("Choose a path:")
Print statement out. If the supplied message ends with a space or tab character, a new line will not be appended.
Example
prompt.say("Simple things.", color: :red)
Ask a question with a list of options
Example:
prompt.select("What size?") do |menu|
menu.choice :large
menu.choices %w(:medium :small)
end
Ask a question with a list of options
Example:
prompt.select("What size?", %w(large medium small))
Ask a question with a range slider
Example:
prompt.slider("What size?", min: 32, max: 54, step: 2)
Ask a yes or no question, with "yes" being the default answer.
Example:
prompt.yes?("Would you like to continue?")
Nested types
- Term::Prompt::AnswersCollector
- Term::Prompt::ArgumentRequired
- Term::Prompt::ArgumentValidation
- Term::Prompt::Autocomplete
- Term::Prompt::BlockPaginator
- Term::Prompt::Choice
- Term::Prompt::Choices
- Term::Prompt::ConfigurationError
- Term::Prompt::ConfirmQuestion
- Term::Prompt::ConversionError
- Term::Prompt::EnhancedConfirm
- Term::Prompt::EnumList
- Term::Prompt::Expander
- Term::Prompt::FileSelect
- Term::Prompt::InvalidArgument
- Term::Prompt::Keypress
- Term::Prompt::List
- Term::Prompt::MaskQuestion
- Term::Prompt::MultiList
- Term::Prompt::Multiline
- Term::Prompt::Paginator
- Term::Prompt::Palette
- Term::Prompt::Question
- Term::Prompt::Result
- Term::Prompt::Slider
- Term::Prompt::Statement
- Term::Prompt::Symbols
- Term::Prompt::ValidationCoercion
- Term::Prompt::Validator
- Term::Prompt::ValidatorProc