From 6acf9b8c635764d5be944e3c39f10d3335a3fcc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Wed, 10 May 2023 15:20:12 +0200 Subject: [PATCH] Add an implicit operator to convert from Color to Style (#1160) --- src/Spectre.Console.Json/JsonText.cs | 18 ++--- .../Progress/Columns/ElapsedTimeColumn.cs | 2 +- .../Live/Progress/Columns/PercentageColumn.cs | 2 +- .../Progress/Columns/ProgressBarColumn.cs | 6 +- .../Progress/Columns/RemainingTimeColumn.cs | 2 +- .../Live/Progress/Columns/SpinnerColumn.cs | 2 +- src/Spectre.Console/Live/Status/Status.cs | 2 +- .../Prompts/MultiSelectionPrompt.cs | 2 +- .../Prompts/SelectionPrompt.cs | 4 +- src/Spectre.Console/Style.cs | 9 +++ src/Spectre.Console/Widgets/Calendar.cs | 2 +- .../Widgets/Exceptions/ExceptionStyle.cs | 16 ++-- src/Spectre.Console/Widgets/ProgressBar.cs | 6 +- .../Widgets/Table/TableRenderer.cs | 4 +- .../Unit/Prompts/TextPromptTests.cs | 76 +++++++++---------- test/Spectre.Console.Tests/Unit/StyleTests.cs | 15 +++- 16 files changed, 95 insertions(+), 73 deletions(-) diff --git a/src/Spectre.Console.Json/JsonText.cs b/src/Spectre.Console.Json/JsonText.cs index 21a83da..4d8c825 100644 --- a/src/Spectre.Console.Json/JsonText.cs +++ b/src/Spectre.Console.Json/JsonText.cs @@ -89,15 +89,15 @@ public sealed class JsonText : JustInTimeRenderable var context = new JsonBuilderContext(new JsonTextStyles { - BracesStyle = BracesStyle ?? new Style(Color.Grey), - BracketsStyle = BracketsStyle ?? new Style(Color.Grey), - MemberStyle = MemberStyle ?? new Style(Color.Blue), - ColonStyle = ColonStyle ?? new Style(Color.Yellow), - CommaStyle = CommaStyle ?? new Style(Color.Grey), - StringStyle = StringStyle ?? new Style(Color.Red), - NumberStyle = NumberStyle ?? new Style(Color.Green), - BooleanStyle = BooleanStyle ?? new Style(Color.Green), - NullStyle = NullStyle ?? new Style(Color.Grey), + BracesStyle = BracesStyle ?? Color.Grey, + BracketsStyle = BracketsStyle ?? Color.Grey, + MemberStyle = MemberStyle ?? Color.Blue, + ColonStyle = ColonStyle ?? Color.Yellow, + CommaStyle = CommaStyle ?? Color.Grey, + StringStyle = StringStyle ?? Color.Red, + NumberStyle = NumberStyle ?? Color.Green, + BooleanStyle = BooleanStyle ?? Color.Green, + NullStyle = NullStyle ?? Color.Grey, }); _syntax.Accept(JsonBuilder.Shared, context); diff --git a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs index a29fdfb..b6e9a65 100644 --- a/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs @@ -11,7 +11,7 @@ public sealed class ElapsedTimeColumn : ProgressColumn /// /// Gets or sets the style of the remaining time text. /// - public Style Style { get; set; } = new Style(foreground: Color.Blue); + public Style Style { get; set; } = Color.Blue; /// public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime) diff --git a/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs b/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs index 0dbef1c..617d6c6 100644 --- a/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/PercentageColumn.cs @@ -13,7 +13,7 @@ public sealed class PercentageColumn : ProgressColumn /// /// Gets or sets the style for a completed task. /// - public Style CompletedStyle { get; set; } = new Style(foreground: Color.Green); + public Style CompletedStyle { get; set; } = Color.Green; /// public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime) diff --git a/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs b/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs index 16c7c19..5a8dc89 100644 --- a/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/ProgressBarColumn.cs @@ -13,17 +13,17 @@ public sealed class ProgressBarColumn : ProgressColumn /// /// Gets or sets the style of completed portions of the progress bar. /// - public Style CompletedStyle { get; set; } = new Style(foreground: Color.Yellow); + public Style CompletedStyle { get; set; } = Color.Yellow; /// /// Gets or sets the style of a finished progress bar. /// - public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green); + public Style FinishedStyle { get; set; } = Color.Green; /// /// Gets or sets the style of remaining portions of the progress bar. /// - public Style RemainingStyle { get; set; } = new Style(foreground: Color.Grey); + public Style RemainingStyle { get; set; } = Color.Grey; /// /// Gets or sets the style of an indeterminate progress bar. diff --git a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs index 3ce467a..9495877 100644 --- a/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs @@ -11,7 +11,7 @@ public sealed class RemainingTimeColumn : ProgressColumn /// /// Gets or sets the style of the remaining time text. /// - public Style Style { get; set; } = new Style(foreground: Color.Blue); + public Style Style { get; set; } = Color.Blue; /// public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime) diff --git a/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs b/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs index 425de14..5b23ccd 100644 --- a/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs +++ b/src/Spectre.Console/Live/Progress/Columns/SpinnerColumn.cs @@ -74,7 +74,7 @@ public sealed class SpinnerColumn : ProgressColumn /// /// Gets or sets the style of the spinner. /// - public Style? Style { get; set; } = new Style(foreground: Color.Yellow); + public Style? Style { get; set; } = Color.Yellow; /// /// Initializes a new instance of the class. diff --git a/src/Spectre.Console/Live/Status/Status.cs b/src/Spectre.Console/Live/Status/Status.cs index 59a1115..7e71d85 100644 --- a/src/Spectre.Console/Live/Status/Status.cs +++ b/src/Spectre.Console/Live/Status/Status.cs @@ -15,7 +15,7 @@ public sealed class Status /// /// Gets or sets the spinner style. /// - public Style? SpinnerStyle { get; set; } = new Style(foreground: Color.Yellow); + public Style? SpinnerStyle { get; set; } = Color.Yellow; /// /// Gets or sets a value indicating whether or not status diff --git a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs index 8c8626b..e1ef43b 100644 --- a/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/MultiSelectionPrompt.cs @@ -225,7 +225,7 @@ public sealed class MultiSelectionPrompt : IPrompt>, IListPromptStrat IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, int cursorIndex, IEnumerable<(int Index, ListPromptItem Node)> items) { var list = new List(); - var highlightStyle = HighlightStyle ?? new Style(foreground: Color.Blue); + var highlightStyle = HighlightStyle ?? Color.Blue; if (Title != null) { diff --git a/src/Spectre.Console/Prompts/SelectionPrompt.cs b/src/Spectre.Console/Prompts/SelectionPrompt.cs index 5835c4a..4b9fdbe 100644 --- a/src/Spectre.Console/Prompts/SelectionPrompt.cs +++ b/src/Spectre.Console/Prompts/SelectionPrompt.cs @@ -137,8 +137,8 @@ public sealed class SelectionPrompt : IPrompt, IListPromptStrategy IRenderable IListPromptStrategy.Render(IAnsiConsole console, bool scrollable, int cursorIndex, IEnumerable<(int Index, ListPromptItem Node)> items) { var list = new List(); - var disabledStyle = DisabledStyle ?? new Style(foreground: Color.Grey); - var highlightStyle = HighlightStyle ?? new Style(foreground: Color.Blue); + var disabledStyle = DisabledStyle ?? Color.Grey; + var highlightStyle = HighlightStyle ?? Color.Blue; if (Title != null) { diff --git a/src/Spectre.Console/Style.cs b/src/Spectre.Console/Style.cs index 9ca844e..ec65222 100644 --- a/src/Spectre.Console/Style.cs +++ b/src/Spectre.Console/Style.cs @@ -132,6 +132,15 @@ public sealed class Style : IEquatable