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

Allow SelectionPrompt to have an initial selection #1541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reduckted
Copy link

fixes #508

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes
  • A maintainer has signed off on the changes and the issue was assigned to me
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors
  • The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

SelectionPrompt now has a DefaultValue property that can be used to set the item that should be initially selected.


Please upvote 👍 this pull request if you are interested in it.

@github-actions github-actions bot added the ⭐ top pull request Top pull request. label May 10, 2024
@timothyparez
Copy link

timothyparez commented Oct 2, 2024

This, for me, is the number one missing feature.
Often we presents the users with a large list of operations
until this PR they had to scroll through the list every time (because they often repeat commands).
Now we simply set the last command they executed as the default.

Just tested this and it works great:

var fruit = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("What's your [green]favorite fruit[/]?")
        .PageSize(10)```
+       .DefaultValue("Banana") // <--- Setting the default value
        .MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
        .AddChoices(new[] {
            "Apple", "Apricot", "Avocado", 
            "Banana", "Blackcurrant", "Blueberry",
            "Cherry", "Cloudberry", "Cocunut",
        }));

AnsiConsole.WriteLine($"I agree. {fruit} is tasty!");

@reduckted reduckted force-pushed the feature/508-selection-prompt-default branch from 1aef241 to e7cb663 Compare October 2, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ top pull request Top pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelectionPrompt - Set default value not available
3 participants