Add support for default choice in selection prompt

Closes #234
This commit is contained in:
Patrik Svensson
2021-01-15 16:32:32 +01:00
committed by Patrik Svensson
parent 63bae278a9
commit 913a7b1e37
3 changed files with 82 additions and 7 deletions

View File

@ -23,6 +23,11 @@ namespace Spectre.Console
/// </summary>
public List<T> Choices { get; }
/// <summary>
/// Gets the initially selected choices.
/// </summary>
public HashSet<int> Selected { get; }
/// <summary>
/// Gets or sets the converter to get the display string for a choice. By default
/// the corresponding <see cref="TypeConverter"/> is used.
@ -52,6 +57,7 @@ namespace Spectre.Console
public MultiSelectionPrompt()
{
Choices = new List<T>();
Selected = new HashSet<int>();
}
/// <inheritdoc/>
@ -73,7 +79,7 @@ namespace Spectre.Console
var converter = Converter ?? TypeConverterHelper.ConvertToString;
var list = new RenderableMultiSelectionList<T>(console, Title, PageSize, Choices, converter, HighlightStyle);
var list = new RenderableMultiSelectionList<T>(console, Title, PageSize, Choices, Selected, converter, HighlightStyle);
using (new RenderHookScope(console, list))
{
console.Cursor.Hide();
@ -114,4 +120,4 @@ namespace Spectre.Console
.ToList();
}
}
}
}