-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Reversible Forms to Prompts #118
Conversation
Converting to draft so @jessarcher can have a look. |
Hey @lukeraymonddowning, This looks really cool! A few questions:
|
Hey @jessarcher! Thanks for the feedback. All changes implemented and ready for review. |
af34036
to
b8422c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great!
Hey all!
This PR adds support for revertable forms to Prompts. Here's a little demo video,
which you can play with for yourself using
php playground/form.php
on this branch.Screen.Recording.2024-04-10.at.10.28.22-1.mov
Purpose
Often, when navigating through a lenthy series of prompts, I make typos or mistakes
and need to go back to make edits. Currently, the only way to fix them is to cancel
the command and start again from scratch.
To fix that frustration, you may now declare a series of steps that the user will
be taken through. By using the
CTRL+U
key combo, any step in the process can bereverted by the user to retry the previous step again.
Usage
A series of steps can be created using the
form
function,followed by the relevant prompt method for each desired step, like so:
Calling
submit
executes the steps in the terminal. In this case, once the user reachesthe "What is your favourite language?" prompt, they can hit
CTRL+U
(alternativelyCMD+BACKSPACE
on Mac)to go back to "What is your name?" and fill it out again.
All prompts that support the
$default
parameter will autofill with the previously entered value when reverting to them, making it easy to fix little typos without having to type everything out again.Utilising previous responses
The
submit
method will return all responses at the end of the run. However, you mayneed access to previous step responses inside of a later step. Each step is passed
an array of all previous responses:
Often, finding the response by index is not a nice experience and can be too brittle. To remedy this, you can provide a
name
for each step, which will be used as the index in the response array:Wrap-up
All in all, I really think this will make life easier and less frustrating for complex prompt sequences. I'm
excited to hear your thoughts!
Thank you for all the hard work maintaining and working on Prompts; it's very much appreciated.
Regards,
Luke