AskTTY
A Ruby gem for interactive terminal prompts.
Installation
Install it globaly:
gem install askttyor, add it to your application gemfile:
bundle add askttyUsage
require "asktty"Input Prompt
name = AskTTY::InputPrompt.ask(
title: "Name",
details: "Enter the name you want displayed on your badge.",
placeholder: "Vlad"
)Text Prompt
notes = AskTTY::TextPrompt.ask(
title: "Ruby Project",
placeholder: "AskTTY\nTerminal prompts for Ruby"
)Select Prompt
drink = AskTTY::SelectPrompt.ask(
title: "Experience Level",
options: [
{ label: "Beginner", value: :beginner },
{ label: "Intermediate", value: :intermediate },
{ label: "Advanced", value: :advanced }
],
value: :intermediate
)MultiSelect Prompt
toppings = AskTTY::MultiSelectPrompt.ask(
title: "Topics",
details: "Select all topics you are interested in.",
options: [
{ label: "Rails", value: :rails },
{ label: "Metaprogramming", value: :metaprogramming },
{ label: "API development", value: :api_development },
{ label: "Background jobs", value: :background_jobs },
{ label: "Testing", value: :testing }
],
values: [:metaprogramming]
)Confirm Prompt
confirmed = AskTTY::ConfirmPrompt.ask(
title: "Confirmation",
details: "Confirm that you plan to attend the event.",
value: true
)Validation
Pass a block that returns true when the current value is valid, or an error message when it is not:
name = AskTTY::InputPrompt.ask(title: "Name") do |value|
value.length >= 3 || "Name must be at least 3 characters"
endExamples
Run the interactive example from the project root:
ruby examples/all_prompts.rbCredit
The prompt UI in AskTTY is based on huh?.
