question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return group in SelectionPrompt and MultiSelectionPrompt

See original GitHub issue

Is your feature request related to a problem? Please describe. I would love when using SelectionPrompt or MultiSelectionPrompt with choice groups, that I could get both the selected item, but also the group it belongs to as output.

Consider this code:

var api = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("What API do you want to explore?")
        .PageSize(10)
        .MoreChoicesText("[grey](Move up and down to reveal more options)[/]")
        .AddChoiceGroup("Cloud API", new string []
        {
            "Booking API"
        })
        .AddChoiceGroup("Site API", new string[]
        {
            "Booking API"
        }));

If I have the same choice in different groups, I would like to know which group it belongs to.

Right now I would have to wrap the strings in my own little class such as:

public class Choice
{
    public string Name { get; set; }
    public string Group { get; set; }

    public override string ToString() => Name;
}

Describe the solution you’d like A clear and concise description of what you want to happen.

Would be great if somehow SelectionPrompt and MultiSelectionPrompt could somehow also return the choice group when returning a value.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
patriksvenssoncommented, Aug 7, 2021

@Cheesebaron I totally get what you’re after, but the problem is that AddChoiceGroup is just a convenience method to add a single level to the tree. It’s also possible to build a selection tree with an arbitrary number of levels.

The result would need to look something like the code below, which I think would make things more complicated than it should be.

public class SelectedChoice<T>
{
    public T Value { get; }
    public bool Selected { get; }
    public Choice<T>? Parent { get; }
}

Perhaps we could add a method to the tree itself to get the parent of a choice?

var group = api.GetParent("Booking API")
0reactions
Cheesebaroncommented, Oct 14, 2021

Go ahead, have been busy with other things. So please do take a stab at it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for Escape key in SelectionPrompt and ...
Basic idea is that prompt ends when user presses Escape key and it somehow indicates to the caller it was cancelled (e.g. by...
Read more >
SelectionPrompt/AddChoice use a Tree (put only the text)
I would like to use the tree (text would be enough) to enrich the selection prompt with more information. Can that be achieved...
Read more >
Use a multi-selection macro variables from a prompt in pass ...
As you see in the code below, I want to bring back records where the values selected by the prompt are in the...
Read more >
Chosen Selector
Multi-Selection Prompt ... How do I create groups of options? ... A group of options is called an “optgroup” and you can define...
Read more >
Multiple Dates in Date Range Filter - Data Management
Hi, I would like to use between operator on multi select date parameter. If the date range filter is [date] between start_date and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found