Skip to content

feat: add support for merging external events into Prompt.custom#2205

Open
lloydrichards wants to merge 2 commits into
Effect-TS:mainfrom
lloydrichards:feat/prompt-events
Open

feat: add support for merging external events into Prompt.custom#2205
lloydrichards wants to merge 2 commits into
Effect-TS:mainfrom
lloydrichards:feat/prompt-events

Conversation

@lloydrichards
Copy link
Copy Markdown
Contributor

Type

  • Feature

Description

I've been wanting a way to link in external data into the Prompt.custom in a way that triggers a re-render without needing to press a key stroke. In the current implementation I need to fake a key stroke using process.stdin as a hack-y work around or build me own render loop from scratch. Ideally what I wanted was an API where I could just pass in a stream of events and be able to trigger the action with the next state:

const eventQueue = yield * Queue.make<number>()

const prompt = Prompt.custom(
  { count: 0 },
  {
    render: (state) => Effect.succeed(`Count: ${state.count}`),
    process: (_input, state) => Effect.succeed(Action.Submit({ value: state.count })),
    clear: () => Effect.succeed(""),
    receive: (value, state) => Effect.succeed(Action.NextFrame({ state: { count: state.count + value } })) // <-- handle events from the dequeue
  },
  Queue.asDequeue(eventQueue) // <-- provide the event queue as a dequeue to the prompt
)

I've been digging around in the Prompt.ts for a while now so I already knew the Terminal.readInput was a Queue and that it shouldn't be too hard to just merge two Queues together.

What I settled on was a type overload where there is the current implementation without the event doing the same thing (non-breaking) and the new type that adds the new events Queue.Dequeued argument and extends the handlers with the received callback. This way adding the queue can be a progressive enhancement on an already functioning user input only prompt.

Some things I needed to mull over:

  • The Prompt isn't responsible for cleaning up the Queue, this needs to be handled by the user
  • There is a very small possibility of an event and a user input happening simultaneously and which one is picked first is indeterministic (I think)
  • Queue needs to not fail (Queue.Dequeue<A, never> so the user is responsible outside of the Prompt to handle these causes.

Related

I wanted to make an issue first but needed to open the repo to poke around in the types and next thing I know I was already halfway through implementing it 🤦‍♂️

Open to other suggestions or requests to change the approach.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 17, 2026

🦋 Changeset detected

Latest commit: 5b3e6bc

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

This PR includes changesets to release 27 packages
Name Type
effect Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/vitest Major
@effect/ai-anthropic Major
@effect/ai-openai-compat Major
@effect/ai-openai Major
@effect/ai-openrouter Major
@effect/atom-react Major
@effect/atom-solid Major
@effect/atom-vue Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-pglite Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/openapi-generator Major

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

@lloydrichards
Copy link
Copy Markdown
Contributor Author

lloydrichards commented May 17, 2026

here are a couple concrete examples of where this would be used:

  • log viewer <- being able to pass in streams logs to show in a scrollable viewport
  • perlin flow <- add a a tickEvent which can move the animation loop along

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant