Closed kke closed 7 years ago
Interesting issue! I feel as though based on my experience that it is pretty much expectation in command line tools on how default values behave. It is impossible to detect whether user wishes to enter empty string or by entering empty string wants to use default value.
If I were to introduce your suggestion of 'pre-filling' default values that may get annoying pretty quickly for some users. I can easily imagine situation where you wish to prompt for few inputs where the defaults simply don't apply to the user. She would have to first delete the default input and then type in what she wanted originally. Having said that, I can also imagine that you could have the input prefilled with default value with a gray colour and when enter is pressed the value is submitted as is and when user starts typing the value is cleared and actual input accepted. Though this still leaves the question of what to do when someone wants to submit empty input. Should they press delete and hence remove default input?
I'm not sure whether the default behaviour should be changed or to allow ask
prompt to accept :prefill
option that changes how defaults are gathered as described above? I want the solution to work for everybody and feel intuitive.
Good point. Harder nut to crack than I anticipated.
Perhaps jump out of the field with tab and get something like select
?
Maybe there could then be default: 'foo'
and suggestions: { ... }
.
Enter foo: (foo) _
* Use empty
* /etc/foo
Of course this could be flipped around and just use:
foo = prompt.select('Foo?') do |menu|
menu.choice 'foo'
menu.choice '<custom>', :custom
end
foo = prompt.ask('Custom foo:") if foo == :custom
The more I think about this request, the more I'm reluctant to change the current behaviour. I'm really struggling to see when and why it would be a good thing to allow for empty input with default option? In your example, does 'Custom foo' being empty make much sense in your tool?
If you really want empty input, then I would probably go with #yes?
prompt to decide whether a user wants to provide custom value or pick default and then having actual boolean flag decide whether #ask
should be shown at all. Would that work?
As guiding principle, I want to keep the prompts as simple as possible and allow them to be combined in powerful ways.
Agreed
You can not enter an empty value to a prompt that has a default value.
So instead of treating empty response to mean "use default", maybe the default value should be prefilled to the input prompt.