{"id":21579303,"url":"https://github.com/neandertech/cue4s","last_synced_at":"2025-06-30T09:33:14.682Z","repository":{"id":251180431,"uuid":"719524106","full_name":"neandertech/cue4s","owner":"neandertech","description":"CLI prompts in Scala 3, available on JS, JVM, and Native platforms","archived":false,"fork":false,"pushed_at":"2025-01-17T19:01:47.000Z","size":258,"stargazers_count":35,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T18:04:06.298Z","etag":null,"topics":["cli","prompts","scala","scala3","scalajs","scalanative","terminal","tui"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neandertech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2023-11-16T10:57:48.000Z","updated_at":"2025-04-04T19:07:47.000Z","dependencies_parsed_at":"2024-11-23T17:19:26.986Z","dependency_job_id":"eec74ddf-17b8-4848-b430-f1e425c532ed","html_url":"https://github.com/neandertech/cue4s","commit_stats":null,"previous_names":["neandertech/cue4s"],"tags_count":7,"template":false,"template_full_name":"indoorvivants/scala3-library-template","purl":"pkg:github/neandertech/cue4s","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neandertech%2Fcue4s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neandertech%2Fcue4s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neandertech%2Fcue4s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neandertech%2Fcue4s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neandertech","download_url":"https://codeload.github.com/neandertech/cue4s/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neandertech%2Fcue4s/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262747921,"owners_count":23358065,"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":["cli","prompts","scala","scala3","scalajs","scalanative","terminal","tui"],"created_at":"2024-11-24T13:12:56.117Z","updated_at":"2025-06-30T09:33:14.655Z","avatar_url":"https://github.com/neandertech.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--toc:start--\u003e\n- [Cue4s](#cue4s)\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [Auto-derivation for case classes](#auto-derivation-for-case-classes)\n  - [Cats Effect integration](#cats-effect-integration)\n  - [Platform support](#platform-support)\n\u003c!--toc:end--\u003e\n\n## Cue4s\n\n[![cue4s Scala version support](https://index.scala-lang.org/neandertech/cue4s/cue4s/latest.svg)](https://index.scala-lang.org/indoorvivants/cue4s/cue4s)\n\nScala 3 library for CLI prompts that works on JVM, JS, and Native.\n\nThe inspiration is taken from a JS library [prompts](https://github.com/terkelg/prompts#options), and the eventual goal is to have cue4s support all the same functionality. \n\nhttps://github.com/user-attachments/assets/c762e557-26a2-4d24-bee2-23dd3443a21b\n\n### Installation\n\n - Scala CLI: `//\u003e using dep tech.neander::cue4s::\u003cversion\u003e`\n - SBT: `libraryDependencies += \"tech.neander\" %%% \"cue4s\" % \"\u003cversion\u003e\"`\n - \n### Usage\n\nThis example is runnable on both JVM and Native (note how we're using `sync`).\nIn fact, if you put into a file named `test.sc` you can run it with [Scala CLI](https://scala-cli.virtuslab.org/).\n\n```scala mdoc:compile-only\n//\u003e using dep tech.neander::cue4s::latest.release\n\nimport cue4s.*\n\nPrompts.sync.use: prompts =\u003e\n  val day = prompts\n    .singleChoice(\"How was your day?\", List(\"great\", \"okay\"))\n    .getOrThrow\n\n  val work = prompts.text(\"Where do you work?\").getOrThrow\n\n  val letters = prompts.multiChoiceAllSelected(\n      \"What are your favourite letters?\",\n      ('A' to 'F').map(_.toString).toList\n    ).getOrThrow\n```\n\nFor this to work on JS, you need to use the `Future`-based methods, example for that is provided in [examples folder](./modules/example/src/main/).\n\n### Auto-derivation for case classes\n\ncue4s includes an experimental auto-derivation for case classes (and only them, currently),\nallowing you to create prompt chains:\n\n```scala mdoc:compile-only\n\n//\u003e using tech.neander::cue4s::latest.release\n\nimport cue4s.*\n\nval validateName: String =\u003e Option[PromptError] = s =\u003e\n    Option.when(s.trim.isEmpty)(PromptError(\"name cannot be empty!\"))\n\ncase class Attributes(\n  @cue(_.text(\"Your name\").validate(validateName))\n  name: String,\n  @cue(_.text(\"Checklist\").multi(\"Wake up\" -\u003e true, \"Grub a brush\" -\u003e true, \"Put a little makeup\" -\u003e false))\n  doneToday: Set[String],\n  @cue(_.text(\"What did you have for breakfast\").options(\"eggs\", \"sadness\"))\n  breakfast: String,\n  @cue(_.text(\"Do you want to build a snowman?\"))\n  snowman: Boolean,\n  @cue(_.text(\"How old are you?\"))\n  age: Int,\n  @cue(_.text(\"What is the value of PI?\"))\n  pi: Float\n) derives PromptChain\n\nval attributes: Attributes = \n  Prompts.sync.use: p =\u003e\n    p.run(PromptChain[Attributes]).getOrThrow\n```\n\nThere is no generic mechanism to define how parameters of different types will be handled, just a set of \nrules that felt right at the time of writing this library:\n\n1. If the type is `String`, and `.options(...)` is present in annotation, the prompt will become `SingleChoice`\n2. If the type is `F[String]` where `F` is one of `List, Vector, Set`, and either `.options(...)` or `.multi(...)` are present,\n   then the prompt will become `MultipleChoice`\n3. If the type is `Option[String]`, then _empty_ value will be turned into `None` (check for emptiness will be run before any validation)\n\nIn the future more combinations can be added.\n\n### Cats Effect integration\n\nA simple Cats Effect integration is provided, which wraps the future-based implementation of terminal interactions. \n\nThe integration is available only for JVM and JS targets.\n\n**Installation**\n\n - Scala CLI: `//\u003e using dep tech.neander::cue4s-cats-effect::\u003cversion\u003e`\n - SBT: `libraryDependencies += \"tech.neander\" %%% \"cue4s-cats-effect\" % \"\u003cversion\u003e\"`\n\n**Usage**\n\n```scala mdoc:compile-only\n//\u003e using dep tech.neander::cue4s-cats-effect::latest.release\n\nimport cue4s.catseffect.*\n\nimport cats.effect.*\nimport cats.syntax.all.*\n\ncase class Info(\n    day: String,\n    work: String,\n    letters: List[String],\n)\n\nobject ioExample extends IOApp.Simple:\n  def run: IO[Unit] =\n    PromptsIO.make.use: prompts =\u003e\n      for\n        _ \u003c- IO.println(\"let's go\")\n\n        day = prompts\n          .singleChoice(\"How was your day?\", List(\"great\", \"okay\"))\n          .map(_.toEither)\n          .flatMap(IO.fromEither)\n\n        work = prompts\n          .text(\"Where do you work?\")\n          .map(_.toEither)\n          .flatMap(IO.fromEither)\n\n        letter = prompts\n          .multiChoiceAllSelected(\n            \"What are your favourite letters?\",\n            ('A' to 'F').map(_.toString).toList,\n          )\n          .map(_.toEither)\n          .flatMap(IO.fromEither)\n\n        info \u003c- (day, work, letter).mapN(Info.apply)\n\n        _ \u003c- IO.println(info)\n      yield ()\n\nend ioExample\n```\n\n### Platform support\n\nOn JS, we can only execute the prompts asynchronously, so the minimal \nusable implementation of a prompt will always return `Future[Completion[Result]]`.\n\nOn JVM and Native, we can execute prompts synchronously, so the simplest \nimplementation returns `Completion[Result]` - but methods wrapping the result in `Future` are provided for convenience.\n\nThis is encoded in the availablity of `sync` and `async` methods on the `Prompts` object (e.g. only `Prompts.async` is available on JS).\n\nThis library is published for Scala.js 1.16.0+, Scala Native 0.5, and JVM.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneandertech%2Fcue4s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneandertech%2Fcue4s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneandertech%2Fcue4s/lists"}