Skip to content
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

Text prompt with editable default value #595

Open
digitaldias opened this issue Oct 22, 2021 · 4 comments
Open

Text prompt with editable default value #595

digitaldias opened this issue Oct 22, 2021 · 4 comments
Labels
feature ⭐ top feature Top feature request. ⭐ top issue Top issue.

Comments

@digitaldias
Copy link

digitaldias commented Oct 22, 2021

Console input is a chore, it'd be nice to be able to pre-fill the user's answer with a default value so that the user can just hit ENTER to proceed to the next question.

I would love the ability to have a prompt that takes a default value, and that makes that editable to the user, which works on PC, Mac, and Linux.


Please upvote 👍 this issue if you are interested in it.

@patriksvensson
Copy link
Contributor

@digitaldias It would make sense to add something like that.
Perhaps adding a property called InsertDefaultValue or similar to TextPrompt and ConfirmationPrompt?

@spectreconsole/maintainers What do you think?

@nils-a
Copy link
Contributor

nils-a commented Oct 22, 2021

I like the idea. I think InitialValue would make more sense as a name. Something like:

new TextPrompt<string>("What's your [green]favorite fruit[/]?")
        .InvalidChoiceMessage("[red]That's not a valid fruit[/]")
        .InitialValue("Orange")
        .AddChoice("Apple")
        .AddChoice("Banana")
        .AddChoice("Orange"));

Should it be possible to set both, the editable default (whatever we call it) and the DefaultValue. I think they are technically not mutually exclusive: The user gets an initial value to edit, and if he removes that completely he'll end up with the default. But does that make sense? Should we disable setting both?

@seiter
Copy link

seiter commented Jul 19, 2022

Like the suggestion, I wonder if it would provide a solution to an issue where validation logic is bypassed when when a DefaultValue is set.

In my case, I expected to be able to provide a default value but have the validation logic run against it, however, with the TextPrompt, validation is bypassed when using DefaultValue as shown in the TextPrompt code listed below:

if (DefaultValue != null)
{
	console.Write(IsSecret ? "******" : converter(DefaultValue.Value), promptStyle);
	console.WriteLine();
	return DefaultValue.Value;
}

Love to see this issue move forward in a way that provides flexibility to use validation logic even when providing an initial (or default) value!

@grenelt
Copy link

grenelt commented Sep 20, 2024

I think a simple option can do it - instead of showing the defaultvalue in front of the prompt it should be shown/inserted in the input buffer after the prompt.

Something like DefaultInput = true|false.

@github-actions github-actions bot added the ⭐ top feature Top feature request. label Sep 26, 2024
@github-actions github-actions bot added the ⭐ top issue Top issue. label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⭐ top feature Top feature request. ⭐ top issue Top issue.
Projects
Status: Todo 🕑
Development

No branches or pull requests

5 participants