mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add interactive prompts for selecting values
* Adds SelectionPrompt * Adds MultiSelectionPrompt Closes #210
This commit is contained in:

committed by
Patrik Svensson

parent
3a593857c8
commit
0e0f4b4220
31
docs/input/prompts/multiselection.md
Normal file
31
docs/input/prompts/multiselection.md
Normal file
@ -0,0 +1,31 @@
|
||||
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)
|
||||
.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);
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user