Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
7.71k stars 245 forks source link

Prompt multi select #3929

Closed joepjoosten closed 6 days ago

joepjoosten commented 2 weeks ago

Type

Description

Added prompt to select multiple choices

changeset-bot[bot] commented 2 weeks ago

🦋 Changeset detected

Latest commit: bdf225420c8dbd261d471da8e70a0cdc218aed9d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------- | ----- | | @effect/cli | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

joepjoosten commented 1 week ago

Scratchpad to see it in action:

import { Command, Prompt } from "@effect/cli"
import { NodeContext, NodeRuntime } from "@effect/platform-node"
import { Array, Console, Effect, pipe } from "effect"

const run = Command.make("example", {}, () =>
  Effect.gen(function*() {
    const choices = pipe(Array.range(1, 20), Array.map((n) => ({ title: `Option ${n}`, value: n })))
    const selectMulti = yield* Prompt.selectMulti({
      message: "select a option",
      choices
    })
    yield* Console.log(`You selected: ${selectMulti.join(", ")}`)
  })).pipe(
    Command.run({
      name: "Test",
      version: "1.0.0"
    })
  )

const main = Effect.suspend(() => run(globalThis.process.argv))

main.pipe(
  Effect.provide(NodeContext.layer),
  Effect.tapErrorCause(Effect.logError),
  NodeRuntime.runMain
)
IMax153 commented 1 week ago

@joepjoosten - thank you so much for all the work you put into this! It looks great so far! I did notice one small thing that I wanted to get your opinion on.

If I select a bunch of options, then invert the selection, and then select all the options, the returned results are out-of-order:

Multi-select reproduction of out of order results

It might be a good idea if we order the results by option number on submission before returning the final list. Wdyt?

IMax153 commented 1 week ago

@joepjoosten - this looks good to me! The only additional request I have is that we make this a patch release since we're only adding a feature, which is backward compatible.

joepjoosten commented 1 week ago

Thanks!

Should i add min/max choices support? Then it can be used in the wizard when there is a repeated choice option?

IMax153 commented 1 week ago

Sure! That would be a cool addition :)

joepjoosten commented 1 week ago

I'm also not really fond of using default text for the select all/none and inverse selection. This is not very international because there in English. I don't know if there are universal symbols for select all/none and inverse?

joepjoosten commented 1 week ago

And nothing more difficult than naming things: "selectMulti", i'm still not happy with this name...

IMax153 commented 1 week ago

And nothing more difficult than naming things: "selectMulti", i'm still not happy with this name...

Maybe MultiSelect instead?

joepjoosten commented 1 week ago

I've added the min max functionality, and renamed it to multiSelect

IMax153 commented 6 days ago

The only additional request I have is that we make this a patch release since we're only adding a feature, which is backward compatible.

@joepjoosten - only one thing left to take care of before we can merge this in 👍

joepjoosten commented 6 days ago

Sorry, i missed that comment. Is this what you mean? (see latest commit)

IMax153 commented 6 days ago

Thanks @joepjoosten !