Skip to content

Commit 3faac78

Browse files
authored
Merge pull request #4641 from patriksvensson/feature/GH-4639
GH-4639: Enable Spectre.Console report printer by default
2 parents 4301942 + d432b33 commit 3faac78

File tree

4 files changed

+79
-25
lines changed

4 files changed

+79
-25
lines changed

src/Cake.Cli/Infrastructure/CakeSpectreReportPrinter.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Write(CakeReport report)
4444
table.AddColumn(
4545
new TableColumn(
4646
new Text("Duration", rowStyle)).Footer(
47-
new Text(FormatTime(GetTotalTime(report)), rowStyle)));
47+
new Text(FormatTime(GetTotalTime(report)).EscapeMarkup(), rowStyle)));
4848

4949
table.AddColumn(
5050
new TableColumn(
@@ -61,16 +61,16 @@ public void Write(CakeReport report)
6161

6262
if (includeSkippedReasonColumn)
6363
{
64-
table.AddRow(new Markup(item.TaskName, itemStyle),
65-
new Markup(FormatDuration(item), itemStyle),
66-
new Markup(item.ExecutionStatus.ToString(), itemStyle),
67-
new Markup(item.SkippedMessage, itemStyle));
64+
table.AddRow(new Markup(item.TaskName.EscapeMarkup(), itemStyle),
65+
new Markup(FormatDuration(item).EscapeMarkup(), itemStyle),
66+
new Markup(item.ExecutionStatus.ToString().EscapeMarkup(), itemStyle),
67+
new Markup(item.SkippedMessage.EscapeMarkup(), itemStyle));
6868
}
6969
else
7070
{
71-
table.AddRow(new Markup(item.TaskName, itemStyle),
72-
new Markup(FormatDuration(item), itemStyle),
73-
new Markup(item.ExecutionStatus.ToString(), itemStyle));
71+
table.AddRow(new Markup(item.TaskName.EscapeMarkup(), itemStyle),
72+
new Markup(FormatDuration(item).EscapeMarkup(), itemStyle),
73+
new Markup(item.ExecutionStatus.ToString().EscapeMarkup(), itemStyle));
7474
}
7575
}
7676

@@ -88,7 +88,7 @@ public void WriteStep(string name, Verbosity verbosity)
8888

8989
var table = new Table().Border(DoubleBorder.Shared);
9090
table.Width(100);
91-
table.AddColumn(name);
91+
table.AddColumn(name.EscapeMarkup());
9292
_console.Write(new Padder(table).Padding(0, 1, 0, 0));
9393
}
9494

@@ -104,7 +104,7 @@ public void WriteLifeCycleStep(string name, Verbosity verbosity)
104104

105105
var table = new Table().Border(SingleBorder.Shared);
106106
table.Width(100);
107-
table.AddColumn(name);
107+
table.AddColumn(name.EscapeMarkup());
108108
_console.Write(table);
109109
}
110110

@@ -118,9 +118,12 @@ public void WriteSkippedStep(string name, Verbosity verbosity)
118118

119119
_console.WriteLine();
120120

121-
var table = new Table().Border(DoubleBorder.Shared);
121+
var table = new Table()
122+
.Border(DoubleBorder.Shared)
123+
.BorderStyle(new Style(ConsoleColor.Gray));
124+
122125
table.Width(100);
123-
table.AddColumn(name);
126+
table.AddColumn(name.EscapeMarkup());
124127
_console.Write(table);
125128
}
126129

src/Cake.Cli/Infrastructure/DoubleBorder.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
4+
#nullable enable
45

56
using Spectre.Console;
67
using Spectre.Console.Rendering;
@@ -15,7 +16,10 @@ public class DoubleBorder : TableBorder
1516
/// <summary>
1617
/// Gets a single instance of the DoubleBorder class.
1718
/// </summary>
18-
public static DoubleBorder Shared { get; } = new DoubleBorder();
19+
public static TableBorder Shared { get; } = new DoubleBorder();
20+
21+
/// <inheritdoc/>
22+
public override TableBorder? SafeBorder => new Safe();
1923

2024
/// <summary>
2125
/// Get information about the custom border.
@@ -26,10 +30,31 @@ public override string GetPart(TableBorderPart part)
2630
{
2731
return part switch
2832
{
29-
TableBorderPart.HeaderTop => "=",
30-
TableBorderPart.FooterBottom => "=",
33+
TableBorderPart.HeaderTopLeft => "═",
34+
TableBorderPart.HeaderTop => "═",
35+
TableBorderPart.HeaderTopRight => "═",
36+
TableBorderPart.FooterBottomLeft => "═",
37+
TableBorderPart.FooterBottom => "═",
38+
TableBorderPart.FooterBottomRight => "═",
3139
_ => string.Empty,
3240
};
3341
}
42+
43+
private sealed class Safe : TableBorder
44+
{
45+
public override string GetPart(TableBorderPart part)
46+
{
47+
return part switch
48+
{
49+
TableBorderPart.HeaderTopLeft => "=",
50+
TableBorderPart.HeaderTop => "=",
51+
TableBorderPart.HeaderTopRight => "=",
52+
TableBorderPart.FooterBottomLeft => "=",
53+
TableBorderPart.FooterBottom => "=",
54+
TableBorderPart.FooterBottomRight => "=",
55+
_ => string.Empty,
56+
};
57+
}
58+
}
3459
}
3560
}

src/Cake.Cli/Infrastructure/SingleBorder.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class SingleBorder : TableBorder
1717
/// </summary>
1818
public static SingleBorder Shared { get; } = new SingleBorder();
1919

20+
/// <inheritdoc/>
21+
public override TableBorder SafeBorder { get; } = new Safe();
22+
2023
/// <summary>
2124
/// Get information about the custom border.
2225
/// </summary>
@@ -26,10 +29,31 @@ public override string GetPart(TableBorderPart part)
2629
{
2730
return part switch
2831
{
29-
TableBorderPart.HeaderTop => "-",
30-
TableBorderPart.FooterBottom => "-",
32+
TableBorderPart.HeaderTopLeft => "─",
33+
TableBorderPart.HeaderTop => "─",
34+
TableBorderPart.HeaderTopRight => "─",
35+
TableBorderPart.FooterBottomLeft => "─",
36+
TableBorderPart.FooterBottom => "─",
37+
TableBorderPart.FooterBottomRight => "─",
3138
_ => string.Empty,
3239
};
3340
}
41+
42+
private sealed class Safe : TableBorder
43+
{
44+
public override string GetPart(TableBorderPart part)
45+
{
46+
return part switch
47+
{
48+
TableBorderPart.HeaderTopLeft => "-",
49+
TableBorderPart.HeaderTop => "-",
50+
TableBorderPart.HeaderTopRight => "-",
51+
TableBorderPart.FooterBottomLeft => "-",
52+
TableBorderPart.FooterBottom => "-",
53+
TableBorderPart.FooterBottomRight => "-",
54+
_ => string.Empty,
55+
};
56+
}
57+
}
3458
}
3559
}

src/Cake/Infrastructure/ContainerConfigurator.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,21 @@ public void Configure(
5757

5858
// Misc registrations.
5959
registrar.RegisterType<CakeReportPrinter>().As<ICakeReportPrinter>().Singleton();
60+
RegisterSpectreConsole(registrar, configuration);
6061

61-
registrar.RegisterInstance(AnsiConsole.Console).As<IAnsiConsole>().Singleton();
62+
registrar.RegisterType<CakeConsole>().As<IConsole>().Singleton();
63+
registrar.RegisterInstance(configuration).As<ICakeConfiguration>().Singleton();
64+
}
6265

63-
var useSpectreConsoleForConsoleOutputString = configuration.GetValue(Constants.Settings.UseSpectreConsoleForConsoleOutput);
64-
var useSpectreConsoleForConsoleOutput = useSpectreConsoleForConsoleOutputString != null && useSpectreConsoleForConsoleOutputString.Equals("true", StringComparison.OrdinalIgnoreCase);
66+
private static void RegisterSpectreConsole(ICakeContainerRegistrar registrar, ICakeConfiguration configuration)
67+
{
68+
registrar.RegisterInstance(AnsiConsole.Console).As<IAnsiConsole>().Singleton();
6569

66-
if (useSpectreConsoleForConsoleOutput)
70+
var useSpectre = configuration.GetValue(Constants.Settings.UseSpectreConsoleForConsoleOutput) ?? "true";
71+
if (useSpectre.Equals("true", StringComparison.OrdinalIgnoreCase))
6772
{
6873
registrar.RegisterType<CakeSpectreReportPrinter>().As<ICakeReportPrinter>().Singleton();
6974
}
70-
71-
registrar.RegisterType<CakeConsole>().As<IConsole>().Singleton();
72-
registrar.RegisterInstance(configuration).As<ICakeConfiguration>().Singleton();
7375
}
7476
}
75-
}
77+
}

0 commit comments

Comments
 (0)