-
Notifications
You must be signed in to change notification settings - Fork 355
Conversation
Hmm you bring up a good point about the interface preventing multiple values being returned from a single prompt... I'll have to think about the right way to do that. Thanks for submitting this, I'll take a look later tonight and let you know if I have any feedback or come up with something - what do we do if the user's response contains a |
btw, I noticed you reverted the Also the validation error changed from I was just trying to mimic what I saw from similar inquirer.js output, but honestly I am not sure how it handles ascii-only terminals. Thanks! |
Yea, i tagged you in the PR reverting the change. I showed the change to a few people around me and they preferred Somewhat related, I have been thinking of adding a flag that would simplify the interaction down to what |
Okay, cool, I just saw the other PR, thanks! I will think about ways to tweak the symbols to allow users to downgrade to ascii if desired without having to copy/paste the entire template. |
Hey Cory, so I did some thinking on this and i'm curious to hear your thoughts. I think the I wonder if this issue is because the interface for thoughts? |
Hey Alec, a few thoughts, first on the symbol replacement, in retrospect I dont think it is too much of a burden to have users fix up the templates to use the symbols desired. For instance if they want to use ascii for Checkbox then this code (although a bit ugly) would get the job done:
Or with a bit more clarity:
Now, for the Prompt interface change ... a type cast would work but feels pretty kludgy to me. I am wondering if it makes more sense to follow the model used by json.Unmarshal where the answer is passed in as a data pointer to be populated by the survey routines. So specifically thinking something like this:
The main routines in survey would looks something like:
Then modify the Question struct to look like:
Where a concrete example of would look like:
I tweaked the code to get a proof of concept and it seems to work. The mess will be with us trying to assign to the passed in interface, so that will either look like a switch/type statement or worst case using reflection. At least in this case the client code will be type safe and we would just have to ensure type safety or return errors. -Cory |
Thinking a bit further, there might be a way to just embed the answer inside the prompt structs like:
Then that would let the interfaces look like:
This would allow concrete types throughout with out any switch/type statements or reflection since inside the logic for each prompt we have guarantees of concrete types. ie Checkbox would look like:
We just have to verify that I will sleep on it a bit and see if this all sounds crazy tomorrow :) |
Hey Alec, other than the multi-value discussion, were there any other changes you want with this PR? I was thinking perhaps the best course of action would be to merge this PR (barring any changes you want) and then we could retrofit this in a secondary PR to deal with any API changes that would be required. You might also want to add a "v0" or a "v1" tag to the repo so that users could always import with something like -Cory |
Hey Cory, thanks for the excellent write up. I'm going to have to think really hard about what to do about this. Also sorry I got a bit distracted. I'm coming to the final stretch of another project i've been working on for a while and that has been keeping my attention away from this problem. I think I prefer to do a mix of what you suggest at the end of your comment. I'd like to keep the interface the same (so checkbox should still return something) but i think I prefer a json encoded list of strings instead of joining them with In the meantime, I'm going to do exactly what you suggest at How does that sound? |
Also, another very minor point but while I've been taking a lot of inspiration from |
Okay, sounds good. I will modify the PR to return JSON for Checkbox and also add an I will also rename Thanks for letting me harass you over the weekend :) |
Not problem at all! Thanks for taking the time to help me build up survey! Just to make sure I conveyed what I was thinking, I don't think we need to add the answers field to any of the other prompts except the MultiSelect since that's the only one that can return non-string values. I'll spend some time thinking about the name on my way to work and if Inhavent formed any opinions by then we'll just go with 'MultiChoice' like u suggest |
Just curious why you don't want the |
I want to be really careful before we make any changes to the interface since we might decide to do something completely different and breaking the API can cause be annoying for consumers. By having |
add MultiChoice to seperate example
Embed `Answer` in MultiChoice struct to allow direct assingment of selected options rather than requiring parsing string response
Thanks for making those changes @coryb I'm going to merge this now. Please let me know if you have any more ideas for this library, i appreciate all your feedback. |
add Checkbox prompt
I have refactored some of the common code from Choice and Checkbox into
multioptions.go
. The event loop it mostly the same, but didnt see an obvious way to abstract it away since I need to handle the "space" key differently for Checkbox.One issue I not sure how to work around is that a Checkbox should return the slice of options checked, but we are limited by the
Prompt() (string, error)
interface which only allows a single string to be returned. My work-around is to just return the list joined by,
character. Users will need to split the answer to get back to a useful result. Not sure if you have ideas there.