diff --git a/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs b/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs index 9646b8f..c720043 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPromptExtensions.cs @@ -122,6 +122,31 @@ public static class MultiSelectionPromptExtensions return obj; } + /// + /// Adds multiple grouped choices. + /// + /// The prompt result type. + /// The prompt. + /// The group. + /// The choices to add. + /// The same instance so that multiple calls can be chained. + public static MultiSelectionPrompt AddChoiceGroup(this MultiSelectionPrompt obj, T group, params T[] choices) + where T : notnull + { + if (obj is null) + { + throw new ArgumentNullException(nameof(obj)); + } + + var root = obj.AddChoice(group); + foreach (var choice in choices) + { + root.AddChild(choice); + } + + return obj; + } + /// /// Marks an item as selected. /// diff --git a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs index 57cd8fe..538ef32 100644 --- a/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/SelectionPromptExtensions.cs @@ -95,6 +95,31 @@ public static class SelectionPromptExtensions return obj; } + /// + /// Adds multiple grouped choices. + /// + /// The prompt result type. + /// The prompt. + /// The group. + /// The choices to add. + /// The same instance so that multiple calls can be chained. + public static SelectionPrompt AddChoiceGroup(this SelectionPrompt obj, T group, params T[] choices) + where T : notnull + { + if (obj is null) + { + throw new ArgumentNullException(nameof(obj)); + } + + var root = obj.AddChoice(group); + foreach (var choice in choices) + { + root.AddChild(choice); + } + + return obj; + } + /// /// Sets the title. ///