diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 3c36d706..12edbf01 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -17,12 +17,6 @@ true - - - - $(NoWarn);CS8620 - - $(NoWarn);AD0001 diff --git a/src/Spectre.Console/AnsiConsole.cs b/src/Spectre.Console/AnsiConsole.cs index 59377878..929d8c49 100644 --- a/src/Spectre.Console/AnsiConsole.cs +++ b/src/Spectre.Console/AnsiConsole.cs @@ -65,4 +65,99 @@ public static partial class AnsiConsole { return _factory.Create(settings); } +} + +// TODO: This is here temporary due to a bug in the .NET SDK +// See issue: https://github.com/dotnet/roslyn/issues/80024 +public static partial class AnsiConsole +{ + /// + /// Writes the text representation of the specified array of objects, + /// to the console using the specified format information. + /// + /// A composite format string. + /// An array of objects to write. + public static void Write(string format, params object[] args) + { + Write(CultureInfo.CurrentCulture, format, args); + } + + /// + /// Writes the text representation of the specified array of objects, + /// to the console using the specified format information. + /// + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void Write(IFormatProvider provider, string format, params object[] args) + { + Console.Write(string.Format(provider, format, args), CurrentStyle); + } + + /// + /// Writes the text representation of the specified array of objects, + /// followed by the current line terminator, to the console + /// using the specified format information. + /// + /// A composite format string. + /// An array of objects to write. + public static void WriteLine(string format, params object[] args) + { + WriteLine(CultureInfo.CurrentCulture, format, args); + } + + /// + /// Writes the text representation of the specified array of objects, + /// followed by the current line terminator, to the console + /// using the specified format information. + /// + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void WriteLine(IFormatProvider provider, string format, params object[] args) + { + Console.WriteLine(string.Format(provider, format, args), CurrentStyle); + } + + /// + /// Writes the specified markup to the console. + /// + /// A composite format string. + /// An array of objects to write. + public static void Markup(string format, params object[] args) + { + Console.Markup(format, args); + } + + /// + /// Writes the specified markup to the console. + /// + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void Markup(IFormatProvider provider, string format, params object[] args) + { + Console.Markup(provider, format, args); + } + + /// + /// Writes the specified markup, followed by the current line terminator, to the console. + /// + /// A composite format string. + /// An array of objects to write. + public static void MarkupLine(string format, params object[] args) + { + Console.MarkupLine(format, args); + } + + /// + /// Writes the specified markup, followed by the current line terminator, to the console. + /// + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void MarkupLine(IFormatProvider provider, string format, params object[] args) + { + Console.MarkupLine(provider, format, args); + } } \ No newline at end of file diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs index 562529da..150aa060 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Markup.cs @@ -2,6 +2,64 @@ namespace Spectre.Console; public static partial class AnsiConsoleExtensions { + /// + /// Writes the specified markup to the console. + /// + /// The console to write to. + /// A composite format string. + /// An array of objects to write. + public static void Markup(this IAnsiConsole console, string format, params object[] args) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + Markup(console, CultureInfo.CurrentCulture, format, args); + } + + /// + /// Writes the specified markup to the console. + /// + /// The console to write to. + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void Markup(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + Markup(console, string.Format(provider, format, args)); + } + + /// + /// Writes the specified markup, followed by the current line terminator, to the console. + /// + /// The console to write to. + /// A composite format string. + /// An array of objects to write. + public static void MarkupLine(this IAnsiConsole console, string format, params object[] args) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + MarkupLine(console, CultureInfo.CurrentCulture, format, args); + } + + /// + /// Writes the specified markup, followed by the current line terminator, to the console. + /// + /// The console to write to. + /// An object that supplies culture-specific formatting information. + /// A composite format string. + /// An array of objects to write. + public static void MarkupLine(this IAnsiConsole console, IFormatProvider provider, string format, params object[] args) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + Markup(console, provider, format + Environment.NewLine, args); + } + extension(AnsiConsole) { /// @@ -13,16 +71,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.Markup(value); } - /// - /// Writes the specified markup to the console. - /// - /// A composite format string. - /// An array of objects to write. - public static void Markup(string format, params object[] args) - { - AnsiConsole.Console.Markup(format, args); - } - /// /// Writes the specified markup to the console. /// @@ -41,17 +89,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.MarkupInterpolated(value); } - /// - /// Writes the specified markup to the console. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public static void Markup(IFormatProvider provider, string format, params object[] args) - { - AnsiConsole.Console.Markup(provider, format, args); - } - /// /// Writes the specified markup to the console. /// @@ -80,16 +117,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.MarkupLine(value); } - /// - /// Writes the specified markup, followed by the current line terminator, to the console. - /// - /// A composite format string. - /// An array of objects to write. - public static void MarkupLine(string format, params object[] args) - { - AnsiConsole.Console.MarkupLine(format, args); - } - /// /// Writes the specified markup, followed by the current line terminator, to the console. /// @@ -108,17 +135,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.MarkupLineInterpolated(value); } - /// - /// Writes the specified markup, followed by the current line terminator, to the console. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public static void MarkupLine(IFormatProvider provider, string format, params object[] args) - { - AnsiConsole.Console.MarkupLine(provider, format, args); - } - /// /// Writes the specified markup, followed by the current line terminator, to the console. /// @@ -142,16 +158,6 @@ public static partial class AnsiConsoleExtensions /// The console to write to. extension(IAnsiConsole console) { - /// - /// Writes the specified markup to the console. - /// - /// A composite format string. - /// An array of objects to write. - public void Markup(string format, params object[] args) - { - Markup(console, CultureInfo.CurrentCulture, format, args); - } - /// /// Writes the specified markup to the console. /// @@ -170,17 +176,6 @@ public static partial class AnsiConsoleExtensions MarkupInterpolated(console, CultureInfo.CurrentCulture, value); } - /// - /// Writes the specified markup to the console. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public void Markup(IFormatProvider provider, string format, params object[] args) - { - Markup(console, string.Format(provider, format, args)); - } - /// /// Writes the specified markup to the console. /// @@ -209,16 +204,6 @@ public static partial class AnsiConsoleExtensions console.Write(MarkupParser.Parse(value)); } - /// - /// Writes the specified markup, followed by the current line terminator, to the console. - /// - /// A composite format string. - /// An array of objects to write. - public void MarkupLine(string format, params object[] args) - { - MarkupLine(console, CultureInfo.CurrentCulture, format, args); - } - /// /// Writes the specified markup, followed by the current line terminator, to the console. /// @@ -246,17 +231,6 @@ public static partial class AnsiConsoleExtensions Markup(console, value + Environment.NewLine); } - /// - /// Writes the specified markup, followed by the current line terminator, to the console. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public void MarkupLine(IFormatProvider provider, string format, params object[] args) - { - Markup(console, provider, format + Environment.NewLine, args); - } - /// /// Writes the specified markup, followed by the current line terminator, to the console. /// diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Write.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Write.cs index 0ea04fb1..39d8c3f2 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Write.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Write.cs @@ -10,7 +10,7 @@ public static partial class AnsiConsoleExtensions /// The value to write. public static void Write(string value) { - Write(value, AnsiConsole.CurrentStyle); + AnsiConsole.Write(value, AnsiConsole.CurrentStyle); } /// @@ -219,29 +219,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.Write(value[index].ToString(provider), AnsiConsole.CurrentStyle); } } - - /// - /// Writes the text representation of the specified array of objects, - /// to the console using the specified format information. - /// - /// A composite format string. - /// An array of objects to write. - public static void Write(string format, params object[] args) - { - Write(CultureInfo.CurrentCulture, format, args); - } - - /// - /// Writes the text representation of the specified array of objects, - /// to the console using the specified format information. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public static void Write(IFormatProvider provider, string format, params object[] args) - { - AnsiConsole.Console.Write(string.Format(provider, format, args), AnsiConsole.CurrentStyle); - } } extension(IAnsiConsole console) diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.WriteLine.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.WriteLine.cs index 564e0f46..6790f42f 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.WriteLine.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.WriteLine.cs @@ -237,31 +237,6 @@ public static partial class AnsiConsoleExtensions AnsiConsole.Console.WriteLine(); } - - /// - /// Writes the text representation of the specified array of objects, - /// followed by the current line terminator, to the console - /// using the specified format information. - /// - /// A composite format string. - /// An array of objects to write. - public static void WriteLine(string format, params object[] args) - { - WriteLine(CultureInfo.CurrentCulture, format, args); - } - - /// - /// Writes the text representation of the specified array of objects, - /// followed by the current line terminator, to the console - /// using the specified format information. - /// - /// An object that supplies culture-specific formatting information. - /// A composite format string. - /// An array of objects to write. - public static void WriteLine(IFormatProvider provider, string format, params object[] args) - { - AnsiConsole.Console.WriteLine(string.Format(provider, format, args), AnsiConsole.CurrentStyle); - } } extension(IAnsiConsole console) diff --git a/src/Spectre.Console/IHasTreeNodes.cs b/src/Spectre.Console/IHasTreeNodes.cs index d9d99791..21cd1dae 100644 --- a/src/Spectre.Console/IHasTreeNodes.cs +++ b/src/Spectre.Console/IHasTreeNodes.cs @@ -16,6 +16,54 @@ public interface IHasTreeNodes /// public static class HasTreeNodeExtensions { + /// + /// Add multiple tree nodes. + /// + /// The object to add the tree node to. + /// The tree nodes to add. + public static void AddNodes(this IHasTreeNodes obj, params string[] nodes) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + ArgumentNullException.ThrowIfNull(nodes); + + obj.Nodes.AddRange(nodes.Select(node => new TreeNode(new Markup(node)))); + } + + /// + /// Add multiple tree nodes. + /// + /// The object to add the tree node to. + /// The tree nodes to add. + public static void AddNodes(this IHasTreeNodes obj, params IRenderable[] nodes) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + ArgumentNullException.ThrowIfNull(nodes); + + obj.Nodes.AddRange(nodes.Select(node => new TreeNode(node))); + } + + /// + /// Add multiple tree nodes. + /// + /// The object to add the tree node to. + /// The tree nodes to add. + public static void AddNodes(this IHasTreeNodes obj, params TreeNode[] nodes) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + ArgumentNullException.ThrowIfNull(nodes); + + obj.Nodes.AddRange(nodes); + } + /// The object to add the tree node to. /// An object with tree nodes. extension(T obj) where T : IHasTreeNodes @@ -27,11 +75,7 @@ public static class HasTreeNodeExtensions /// The added tree node. public TreeNode AddNode(string markup) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(markup); return AddNode(obj, new Markup(markup)); @@ -44,11 +88,7 @@ public static class HasTreeNodeExtensions /// The added tree node. public TreeNode AddNode(IRenderable renderable) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(renderable); var node = new TreeNode(renderable); @@ -63,108 +103,44 @@ public static class HasTreeNodeExtensions /// The added tree node. public TreeNode AddNode(TreeNode node) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(node); obj.Nodes.Add(node); return node; } - /// - /// Add multiple tree nodes. - /// - /// The tree nodes to add. - public void AddNodes(params string[] nodes) - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - ArgumentNullException.ThrowIfNull(nodes); - - obj.Nodes.AddRange(nodes.Select(node => new TreeNode(new Markup(node)))); - } - /// /// Add multiple tree nodes. /// /// The tree nodes to add. public void AddNodes(IEnumerable nodes) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(nodes); obj.Nodes.AddRange(nodes.Select(node => new TreeNode(new Markup(node)))); } - /// - /// Add multiple tree nodes. - /// - /// The tree nodes to add. - public void AddNodes(params IRenderable[] nodes) - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - ArgumentNullException.ThrowIfNull(nodes); - - obj.Nodes.AddRange(nodes.Select(node => new TreeNode(node))); - } - /// /// Add multiple tree nodes. /// /// The tree nodes to add. public void AddNodes(IEnumerable nodes) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(nodes); obj.Nodes.AddRange(nodes.Select(node => new TreeNode(node))); } - /// - /// Add multiple tree nodes. - /// - /// The tree nodes to add. - public void AddNodes(params TreeNode[] nodes) - { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - - ArgumentNullException.ThrowIfNull(nodes); - - obj.Nodes.AddRange(nodes); - } - /// /// Add multiple tree nodes. /// /// The tree nodes to add. public void AddNodes(IEnumerable nodes) { - if (obj is null) - { - throw new ArgumentNullException(nameof(obj)); - } - + ArgumentNullException.ThrowIfNull(obj); ArgumentNullException.ThrowIfNull(nodes); obj.Nodes.AddRange(nodes); diff --git a/src/Spectre.Console/Live/Progress/Progress.cs b/src/Spectre.Console/Live/Progress/Progress.cs index 545645e2..a08853e9 100644 --- a/src/Spectre.Console/Live/Progress/Progress.cs +++ b/src/Spectre.Console/Live/Progress/Progress.cs @@ -171,31 +171,34 @@ public sealed class Progress /// public static class ProgressExtensions { + /// + /// Sets the columns to be used for an instance. + /// + /// The instance. + /// The columns to use. + /// The same instance so that multiple calls can be chained. + public static Progress Columns(this Progress progress, params ProgressColumn[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(progress); + ArgumentNullException.ThrowIfNull(columns); + + if (!columns.Any()) + { + throw new InvalidOperationException("At least one column must be specified."); + } + + progress.Columns.Clear(); + progress.Columns.AddRange(columns); + + return progress; + } + /// The instance. extension(Progress progress) { - /// - /// Sets the columns to be used for an instance. - /// - /// The columns to use. - /// The same instance so that multiple calls can be chained. - public Progress Columns(params ProgressColumn[] columns) - { - ArgumentNullException.ThrowIfNull(progress); - - ArgumentNullException.ThrowIfNull(columns); - - if (!columns.Any()) - { - throw new InvalidOperationException("At least one column must be specified."); - } - - progress.Columns.Clear(); - progress.Columns.AddRange(columns); - - return progress; - } - /// /// Sets an optional hook to intercept rendering. /// @@ -204,7 +207,6 @@ public static class ProgressExtensions public Progress UseRenderHook(Func, IRenderable> renderHook) { progress.RenderHook = renderHook; - return progress; } @@ -217,9 +219,7 @@ public static class ProgressExtensions public Progress AutoRefresh(bool enabled) { ArgumentNullException.ThrowIfNull(progress); - progress.AutoRefresh = enabled; - return progress; } @@ -233,9 +233,7 @@ public static class ProgressExtensions public Progress AutoClear(bool enabled) { ArgumentNullException.ThrowIfNull(progress); - progress.AutoClear = enabled; - return progress; } @@ -249,9 +247,7 @@ public static class ProgressExtensions public Progress HideCompleted(bool enabled) { ArgumentNullException.ThrowIfNull(progress); - progress.HideCompleted = enabled; - return progress; } } diff --git a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs index c358f35f..407d4ecb 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs @@ -95,7 +95,8 @@ public sealed class MultiSelectionPrompt : IPrompt>, IListPromptStrat // Create the list prompt var prompt = new ListPrompt(console, this); var converter = Converter ?? TypeConverterHelper.ConvertToString; - var result = await prompt.Show(Tree, converter, Mode, false, false, PageSize, WrapAround, cancellationToken).ConfigureAwait(false); + var result = await prompt.Show(Tree, converter, Mode, false, false, PageSize, WrapAround, cancellationToken) + .ConfigureAwait(false); if (Mode == SelectionMode.Leaf) { @@ -248,9 +249,12 @@ public sealed class MultiSelectionPrompt : IPrompt>, IListPromptStrat var style = current ? highlightStyle : Style.Plain; var indent = new string(' ', item.Node.Depth * 2); - var prompt = item.Index == cursorIndex ? ListPromptConstants.Arrow : new string(' ', ListPromptConstants.Arrow.Length); + var prompt = item.Index == cursorIndex + ? ListPromptConstants.Arrow + : new string(' ', ListPromptConstants.Arrow.Length); - var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(item.Node.Data) ?? item.Node.Data.ToString() ?? "?"; + var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(item.Node.Data) ?? + item.Node.Data.ToString() ?? "?"; if (current) { text = text.RemoveMarkup().EscapeMarkup(); @@ -285,6 +289,56 @@ public sealed class MultiSelectionPrompt : IPrompt>, IListPromptStrat /// public static class MultiSelectionPromptExtensions { + /// + /// Adds multiple choices. + /// + /// The prompt result type. + /// The prompt. + /// The choices to add. + /// The same instance so that multiple calls can be chained. + public static MultiSelectionPrompt AddChoices( + this MultiSelectionPrompt obj, + params T[] choices) where T : notnull + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + + foreach (var choice in choices) + { + obj.AddChoice(choice); + } + + 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 + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + + var root = obj.AddChoice(group); + foreach (var choice in choices) + { + root.AddChild(choice); + } + + return obj; + } + /// The prompt. /// The prompt result type. extension(MultiSelectionPrompt obj) where T : notnull @@ -320,23 +374,6 @@ public static class MultiSelectionPromptExtensions return obj; } - /// - /// Adds multiple choices. - /// - /// The choices to add. - /// The same instance so that multiple calls can be chained. - public MultiSelectionPrompt AddChoices(params T[] choices) - { - ArgumentNullException.ThrowIfNull(obj); - - foreach (var choice in choices) - { - obj.AddChoice(choice); - } - - return obj; - } - /// /// Adds multiple choices. /// @@ -373,25 +410,6 @@ public static class MultiSelectionPromptExtensions return obj; } - /// - /// Adds multiple grouped choices. - /// - /// The group. - /// The choices to add. - /// The same instance so that multiple calls can be chained. - public MultiSelectionPrompt AddChoiceGroup(T group, params T[] choices) - { - ArgumentNullException.ThrowIfNull(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/SelectionPrompt.cs b/src/Spectre.Console/Prompts/SelectionPrompt.cs index 8bd18d19..6885c260 100644 --- a/src/Spectre.Console/Prompts/SelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/SelectionPrompt.cs @@ -235,6 +235,55 @@ public sealed class SelectionPrompt : IPrompt, IListPromptStrategy /// public static class SelectionPromptExtensions { + /// + /// Adds multiple choices. + /// + /// The prompt. + /// The choices to add. + /// The same instance so that multiple calls can be chained. + public static SelectionPrompt AddChoices( + this SelectionPrompt obj, + params T[] choices) where T : notnull + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + + foreach (var choice in choices) + { + obj.AddChoice(choice); + } + + 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 + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(obj); + + var root = obj.AddChoice(group); + foreach (var choice in choices) + { + root.AddChild(choice); + } + + return obj; + } + /// The prompt. /// The prompt result type. extension(SelectionPrompt obj) where T : notnull @@ -252,23 +301,6 @@ public static class SelectionPromptExtensions return obj; } - /// - /// Adds multiple choices. - /// - /// The choices to add. - /// The same instance so that multiple calls can be chained. - public SelectionPrompt AddChoices(params T[] choices) - { - ArgumentNullException.ThrowIfNull(obj); - - foreach (var choice in choices) - { - obj.AddChoice(choice); - } - - return obj; - } - /// /// Adds multiple choices. /// @@ -305,25 +337,6 @@ public static class SelectionPromptExtensions return obj; } - /// - /// Adds multiple grouped choices. - /// - /// The group. - /// The choices to add. - /// The same instance so that multiple calls can be chained. - public SelectionPrompt AddChoiceGroup(T group, params T[] choices) - { - ArgumentNullException.ThrowIfNull(obj); - - var root = obj.AddChoice(group); - foreach (var choice in choices) - { - root.AddChild(choice); - } - - return obj; - } - /// /// Sets the title. /// diff --git a/src/Spectre.Console/Widgets/Grid.cs b/src/Spectre.Console/Widgets/Grid.cs index 539b48dc..644f7397 100644 --- a/src/Spectre.Console/Widgets/Grid.cs +++ b/src/Spectre.Console/Widgets/Grid.cs @@ -146,6 +146,46 @@ public sealed class Grid : JustInTimeRenderable, IExpandable, IAlignable /// public static class GridExtensions { + /// + /// Adds a new row to the grid. + /// + /// The grid to add the column to. + /// The columns to add. + /// The same instance so that multiple calls can be chained. + public static Grid AddRow(this Grid grid, params string[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(grid); + ArgumentNullException.ThrowIfNull(columns); + + grid.AddRow(columns.Select(column => new Markup(column)).ToArray()); + return grid; + } + + /// + /// Adds a column to the grid. + /// + /// The grid to add the column to. + /// The columns to add. + /// The same instance so that multiple calls can be chained. + public static Grid AddColumns(this Grid grid, params GridColumn[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(grid); + ArgumentNullException.ThrowIfNull(columns); + + foreach (var column in columns) + { + grid.AddColumn(column); + } + + return grid; + } + /// The grid to add the column to. extension(Grid grid) { @@ -166,25 +206,6 @@ public static class GridExtensions return grid; } - /// - /// Adds a column to the grid. - /// - /// The columns to add. - /// The same instance so that multiple calls can be chained. - public Grid AddColumns(params GridColumn[] columns) - { - ArgumentNullException.ThrowIfNull(grid); - - ArgumentNullException.ThrowIfNull(columns); - - foreach (var column in columns) - { - grid.AddColumn(column); - } - - return grid; - } - /// /// Adds an empty row to the grid. /// @@ -200,21 +221,6 @@ public static class GridExtensions return grid; } - /// - /// Adds a new row to the grid. - /// - /// The columns to add. - /// The same instance so that multiple calls can be chained. - public Grid AddRow(params string[] columns) - { - ArgumentNullException.ThrowIfNull(grid); - - ArgumentNullException.ThrowIfNull(columns); - - grid.AddRow(columns.Select(column => new Markup(column)).ToArray()); - return grid; - } - /// /// Sets the grid width. /// diff --git a/src/Spectre.Console/Widgets/Table/Table.cs b/src/Spectre.Console/Widgets/Table/Table.cs index 0db1acfc..d1fc341d 100644 --- a/src/Spectre.Console/Widgets/Table/Table.cs +++ b/src/Spectre.Console/Widgets/Table/Table.cs @@ -168,28 +168,121 @@ public sealed class Table : Renderable, IHasTableBorder, IExpandable, IAlignable /// public static class TableExtensions { + /// + /// Adds multiple columns to the table. + /// + /// The table to add the column to. + /// The columns to add. + /// The same instance so that multiple calls can be chained. + public static Table AddColumns(this Table table, params TableColumn[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + ArgumentNullException.ThrowIfNull(columns); + + foreach (var column in columns) + { + table.AddColumn(column); + } + + return table; + } + + /// + /// Adds a row to the table. + /// + /// The table to add the column to. + /// The row columns to add. + /// The same instance so that multiple calls can be chained. + public static Table AddRow(this Table table, params IRenderable[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + + return table.AddRow((IEnumerable)columns); + } + + /// + /// Adds multiple columns to the table. + /// + /// The table to add the column to. + /// The columns to add. + /// The same instance so that multiple calls can be chained. + public static Table AddColumns(this Table table, params string[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + ArgumentNullException.ThrowIfNull(columns); + + foreach (var column in columns) + { + AddColumn(table, column); + } + + return table; + } + + /// + /// Adds a row to the table. + /// + /// The table to add the column to. + /// The row columns to add. + /// The same instance so that multiple calls can be chained. + public static Table AddRow(this Table table, params string[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + ArgumentNullException.ThrowIfNull(columns); + + table.AddRow(columns.Select(column => new Markup(column)).ToArray()); + return table; + } + + /// + /// Inserts a row in the table at the specified index. + /// + /// The table to add the column to. + /// The index to insert the row at. + /// The row columns to add. + /// The same instance so that multiple calls can be chained. + public static Table InsertRow(this Table table, int index, params IRenderable[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + + return InsertRow(table, index, (IEnumerable)columns); + } + + /// + /// Inserts a row in the table at the specified index. + /// + /// The table to add the column to. + /// The index to insert the row at. + /// The row columns to add. + /// The same instance so that multiple calls can be chained. + public static Table InsertRow(this Table table, int index, params string[] columns) + { + // TODO: This is here temporary due to a bug in the .NET SDK + // See issue: https://github.com/dotnet/roslyn/issues/80024 + + ArgumentNullException.ThrowIfNull(table); + + return InsertRow(table, index, columns.Select(column => new Markup(column))); + } + /// The table to add the column to. extension(Table table) { - /// - /// Adds multiple columns to the table. - /// - /// The columns to add. - /// The same instance so that multiple calls can be chained. - public Table AddColumns(params TableColumn[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - ArgumentNullException.ThrowIfNull(columns); - - foreach (var column in columns) - { - table.AddColumn(column); - } - - return table; - } - /// /// Adds a row to the table. /// @@ -205,18 +298,6 @@ public static class TableExtensions return table; } - /// - /// Adds a row to the table. - /// - /// The row columns to add. - /// The same instance so that multiple calls can be chained. - public Table AddRow(params IRenderable[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - return table.AddRow((IEnumerable)columns); - } - /// /// Adds an empty row to the table. /// @@ -250,40 +331,6 @@ public static class TableExtensions return table; } - /// - /// Adds multiple columns to the table. - /// - /// The columns to add. - /// The same instance so that multiple calls can be chained. - public Table AddColumns(params string[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - ArgumentNullException.ThrowIfNull(columns); - - foreach (var column in columns) - { - AddColumn(table, column); - } - - return table; - } - - /// - /// Adds a row to the table. - /// - /// The row columns to add. - /// The same instance so that multiple calls can be chained. - public Table AddRow(params string[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - ArgumentNullException.ThrowIfNull(columns); - - table.AddRow(columns.Select(column => new Markup(column)).ToArray()); - return table; - } - /// /// Inserts a row in the table at the specified index. /// @@ -336,32 +383,6 @@ public static class TableExtensions return table; } - /// - /// Inserts a row in the table at the specified index. - /// - /// The index to insert the row at. - /// The row columns to add. - /// The same instance so that multiple calls can be chained. - public Table InsertRow(int index, params IRenderable[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - return InsertRow(table, index, (IEnumerable)columns); - } - - /// - /// Inserts a row in the table at the specified index. - /// - /// The index to insert the row at. - /// The row columns to add. - /// The same instance so that multiple calls can be chained. - public Table InsertRow(int index, params string[] columns) - { - ArgumentNullException.ThrowIfNull(table); - - return InsertRow(table, index, columns.Select(column => new Markup(column))); - } - /// /// Removes a row from the table with the specified index. ///