feat: add support for merging external events into Prompt.custom#2205
Open
lloydrichards wants to merge 2 commits into
Open
feat: add support for merging external events into Prompt.custom#2205lloydrichards wants to merge 2 commits into
Prompt.custom#2205lloydrichards wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 5b3e6bc The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
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 |
6b3813e to
5b3e6bc
Compare
Contributor
Author
|
here are a couple concrete examples of where this would be used:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Description
I've been wanting a way to link in external data into the
Prompt.customin 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 usingprocess.stdinas 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:I've been digging around in the Prompt.ts for a while now so I already knew the
Terminal.readInputwas 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
eventsQueue.Dequeued argument and extends the handlers with thereceivedcallback. 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:
Promptisn't responsible for cleaning up theQueue, this needs to be handled by the userQueue.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.