{"id":17065921,"url":"https://github.com/fractaledmind/prompts","last_synced_at":"2025-04-13T02:18:41.135Z","repository":{"id":252049351,"uuid":"839254740","full_name":"fractaledmind/prompts","owner":"fractaledmind","description":"Beautiful and user-friendly forms for your command-line Ruby applications.","archived":false,"fork":false,"pushed_at":"2024-10-08T14:31:06.000Z","size":73,"stargazers_count":125,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T04:12:22.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fractaledmind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-07T08:48:16.000Z","updated_at":"2025-01-23T07:07:12.000Z","dependencies_parsed_at":"2024-08-07T12:32:05.015Z","dependency_job_id":"23e295c2-b757-435e-b2b3-4a3d5a921882","html_url":"https://github.com/fractaledmind/prompts","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.021276595744680882","last_synced_commit":"fe252adedfac5fa19b5cdc82d073a2212834b254"},"previous_names":["fractaledmind/prompts"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Fprompts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Fprompts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Fprompts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractaledmind%2Fprompts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fractaledmind","download_url":"https://codeload.github.com/fractaledmind/prompts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654205,"owners_count":21140262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T11:01:35.231Z","updated_at":"2025-04-13T02:18:41.104Z","avatar_url":"https://github.com/fractaledmind.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Prompts\n\nPrompts helps you to add beautiful and user-friendly forms to your command-line applications, with browser-like features including label text, help text, validation, and inline errors.\n\nIt was originally inspired by the [Laravel Prompts](https://laravel.com/docs/11.x/prompts) package.\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n```bash\nbundle add prompts\n```\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n```bash\ngem install prompts\n```\n\n## Philosophy\n\nPrompts aims to provide beautiful and user-friendly forms for your command-line applications while keeping both the API and the implementation simple. This means Prompts is built with constraints in mind.\n\nIn order to minimize complexity, we build on top of the excellent [`reline`](https://github.com/ruby/reline) gem to provide a full-featured text input. Similarly, the text input is **always** rendered at the bottom of the screen. And inputing text is the **only** way to interact with the form.\n\nIn this way, this new library is similar to [Charm's Huh library](https://github.com/charmbracelet/huh) when used in \"accessible\" mode. But, with some UX improvements added to this interaction. Instead of simply appending new fields to the screen, Prompts' forms act like wizards 🧙‍♂️. Each field gets its own screen, and on each render loop, the screen is reset and repainted.\n\nFinally, to keep internals simple, Prompts expects users to build and provide their own ANSI-formatted strings. However, we do make available the [`fmt`](https://github.com/hopsoft/fmt) gem as the recommended way to generate well formatted ANSI strings.\n\n## Available Prompts\n\n### Text\n\nA `Text` prompt will prompt the user with the given question, accept their input, and then return it:\n\n```ruby\nname = Prompts::TextPrompt.ask(label: \"What is your name?\")\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eWhat is your name?\u003c/b\u003e \u003cem\u003e(Press Enter to submit)\u003c/em\u003e\n   \u003cb\u003eType your response and press Enter ⏎\u003c/b\u003e\n\n   \u003cb\u003e\u003e\u003c/b\u003e |\n\u003c/pre\u003e\n\nYou may also include a default value and an informational hint:\n\n```ruby\nname = Prompts::TextPrompt.ask(\n  label: \"What is your name?\",\n  default: \"John Doe\",\n  hint: \"This will be displayed on your profile.\"\n)\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eWhat is your name?\u003c/b\u003e \u003cem\u003e(Press Enter to submit)\u003c/em\u003e\n   \u003cb\u003eThis will be displayed on your profile.\u003c/b\u003e\n\n   \u003cb\u003e\u003e\u003c/b\u003e John Doe|\n\u003c/pre\u003e\n\n#### Required values\n\nIf you require a value to be entered, you may pass the `required` argument:\n\n```ruby\nname = Prompts::TextPrompt.ask(\n  label: \"What is your name?\",\n  required: true\n)\n```\n\nIf you would like to customize the validation message, you may also pass a string:\n\n```ruby\nname = Prompts::TextPrompt.ask(\n  label: \"What is your name?\",\n  required: \"Your name is required.\"\n)\n```\n\n#### Additional Validation\n\nFinally, if you would like to perform additional validation logic, you may pass a block/proc to the validate argument:\n\n```ruby\nname = Prompts::TextPrompt.ask(\n  label: \"What is your name?\",\n  validate: -\u003e(value) do\n    if value.length \u003c 3\n      \"The name must be at least 3 characters.\"\n    elsif value.length \u003e 255\n      \"The name must not exceed 255 characters.\"\n    end\n  end\n)\n```\n\nThe block will receive the value that has been entered and may return an error message, or `nil` if the validation passes.\n\n### Select\n\nIf you need the user to select from a predefined set of choices, you may use the `Select` prompt:\n\n```ruby\nrole = Prompts::SelectPrompt.ask(\n  label: \"What role should the user have?\",\n  options: [\"Member\", \"Contributor\", \"Owner\"]\n)\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eWhat role should the user have?\u003c/b\u003e \u003cem\u003e(Enter the number of your choice)\u003c/em\u003e\n   \u003cb\u003eType your response and press Enter ⏎\u003c/b\u003e\n   \u003cb\u003e1.\u003c/b\u003e Member\n   \u003cb\u003e2.\u003c/b\u003e Contributor\n   \u003cb\u003e3.\u003c/b\u003e Owner\n\n   \u003cb\u003e\u003e\u003c/b\u003e |\n\u003c/pre\u003e\n\nYou may also include a default value and an informational hint:\n\n```ruby\nrole = Prompts::SelectPrompt.ask(\n  label: \"What role should the user have?\",\n  options: [\"Member\", \"Contributor\", \"Owner\"],\n  default: \"Owner\",\n  hint: \"The role may be changed at any time.\"\n)\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eWhat role should the user have?\u003c/b\u003e \u003cem\u003e(Enter the number of your choice)\u003c/em\u003e\n   \u003cb\u003eThe role may be changed at any time.\u003c/b\u003e\n   \u003cb\u003e1.\u003c/b\u003e Member\n   \u003cb\u003e2.\u003c/b\u003e Contributor\n   \u003cb\u003e3.\u003c/b\u003e Owner\n\n   \u003cb\u003e\u003e\u003c/b\u003e 3|\n\u003c/pre\u003e\n\nYou may also pass a hash to the `options` argument to have the selected key returned instead of its value:\n\n```ruby\nrole = Prompts::SelectPrompt.ask(\n  label: \"What role should the user have?\",\n  options: {\n    member: \"Member\",\n    contributor: \"Contributor\",\n    owner: \"Owner\",\n  },\n  default: \"owner\"\n)\n```\n\n#### Additional Validation\n\nUnlike other prompt classes, the `SelectPrompt` doesn't accept the `required` argument because it is not possible to select nothing. However, you may pass a block/proc to the `validate` argument if you need to present an option but prevent it from being selected:\n\n```ruby\nrole = Prompts::SelectPrompt.ask(\n  label: \"What role should the user have?\",\n  options: {\n    member: \"Member\",\n    contributor: \"Contributor\",\n    owner: \"Owner\",\n  },\n  validate: -\u003e(value) do\n    if value == \"owner\" \u0026\u0026 User.where(role: \"owner\").exists?\n      \"An owner already exists.\"\n    end\n  end\n)\n```\n\nIf the `options` argument is a hash, then the block will receive the selected key, otherwise it will receive the selected value. The block may return an error message, or `nil` if the validation passes.\n\n### Confirm\n\nIf you need to ask the user for a \"yes or no\" confirmation, you may use the `ConfirmPrompt`. Users may press `y` or `n` (or `Y` or `N`) to select their response. This function will return either `true` or `false`.\n\n```ruby\nconfirmed = Prompts::ConfirmPrompt.ask(label: \"Do you accept the terms?\")\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eDo you accept the terms?\u003c/b\u003e \u003cem\u003e(Press Enter to submit)\u003c/em\u003e\n\n   \u003cb\u003eChoose [y/n]:\u003c/b\u003e |\n\u003c/pre\u003e\n\nYou may also include a default value and an informational hint:\n\n```ruby\nconfirmed = Prompts::ConfirmPrompt.ask(\n  label: \"Do you accept the terms?\",\n  default: false,\n  hint: \"The terms must be accepted to continue.\",\n)\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003eDo you accept the terms?\u003c/b\u003e \u003cem\u003e(Press Enter to submit)\u003c/em\u003e\n   \u003cb\u003eThe terms must be accepted to continue.\u003c/b\u003e\n\n   \u003cb\u003eChoose [y/N]:\u003c/b\u003e |\n\u003c/pre\u003e\n\n#### Requiring \"Yes\"\n\nIf necessary, you may require your users to select \"Yes\" by passing the `required` argument:\n\n```ruby\nconfirmed = Prompts::ConfirmPrompt.ask(\n  label: \"Do you accept the terms?\",\n  required: true\n)\n```\n\nIf you would like to customize the validation message, you may also pass a string:\n\n```ruby\nconfirmed = Prompts::ConfirmPrompt.ask(\n  label: \"Do you accept the terms?\",\n  required: \"You must accept the terms to continue.\"\n)\n```\n\n### Pause\n\nThe `PausePrompt` may be used to display informational text to the user and wait for them to confirm their desire to proceed by pressing the Enter / Return key:\n\n```ruby\nPrompts::PausePrompt.ask\n```\n\nwhich generates a terminal screen like this (this representation doesn't show color):\n\u003cpre\u003e\n\n   \u003cb\u003ePress Enter ⏎ to continue...\u003c/b\u003e |\n\u003c/pre\u003e\n\n## Forms\n\nOften, you will have multiple prompts that will be displayed in sequence to collect information before performing additional actions. You may use the `Prompts::Form` class to create a grouped set of prompts for the user to complete:\n\n```ruby\nresponses = Prompts::Form.submit do |form|\n  form.text(\n    label: \"What is your name?\",\n    required: true\n  )\n  form.select(\n    label: \"What role should the user have?\",\n    options: {\n      member: \"Member\",\n      contributor: \"Contributor\",\n      owner: \"Owner\",\n    }\n  )\n  form.confirm(\n    label: 'Do you accept the terms?'\n  )\nend\n```\n\nThe `submit` method will return a numerically indexed hash containing all of the responses from the form's prompts. However, you may provide a name for each prompt via the `name` argument. When a name is provided, the named prompt's response may be accessed via that name:\n\n```ruby\nresponses = Prompts::Form.submit do |form|\n  form.text(\n    label: \"What is your name?\",\n    required: true,\n    name: :name\n  )\n  form.select(\n    label: \"What role should the user have?\",\n    options: {\n      member: \"Member\",\n      contributor: \"Contributor\",\n      owner: \"Owner\",\n    },\n    name: :role\n  )\n  form.confirm(\n    label: 'Do you accept the terms?',\n    name: :terms\n  )\nend\n\nUser.create(\n  name: responses[:name],\n  role: responses[:role],\n  terms: responses[:terms]\n)\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/prompts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/fractaledmind/prompts/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Prompts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fractaledmind/prompts/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractaledmind%2Fprompts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffractaledmind%2Fprompts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractaledmind%2Fprompts/lists"}