mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
35 lines
1.0 KiB
Markdown
35 lines
1.0 KiB
Markdown
Title: Multi Selection
|
|
Order: 3
|
|
---
|
|
|
|
The `MultiSelectionPrompt` can be used when you want the user to select
|
|
one or many items from a provided list.
|
|
|
|
<img src="../assets/images/multiselection.gif" style="width: 100%;" />
|
|
|
|
# Usage
|
|
|
|
```csharp
|
|
// Ask for the user's favorite fruits
|
|
var fruits = AnsiConsole.Prompt(
|
|
new MultiSelectionPrompt<string>()
|
|
.Title("What are your [green]favorite fruits[/]?")
|
|
.NotRequired() // Not required to have a favorite fruit
|
|
.PageSize(10)
|
|
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
|
|
.InstructionsText(
|
|
"[grey](Press [blue]<space>[/] to toggle a fruit, " +
|
|
"[green]<enter>[/] to accept)[/]")
|
|
.AddChoice("Apple")
|
|
.AddChoices(new[] {
|
|
"Apricot", "Avocado",
|
|
"Banana", "Blackcurrant", "Blueberry",
|
|
"Cherry", "Cloudberry", "Cocunut",
|
|
}));
|
|
|
|
// Write the selected fruits to the terminal
|
|
foreach (string fruit in fruits)
|
|
{
|
|
AnsiConsole.WriteLine(fruit);
|
|
}
|
|
``` |