Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/Cake.Cli/Infrastructure/CakeSpectreReportPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Write(CakeReport report)
table.AddColumn(
new TableColumn(
new Text("Duration", rowStyle)).Footer(
new Text(FormatTime(GetTotalTime(report)), rowStyle)));
new Text(FormatTime(GetTotalTime(report)).EscapeMarkup(), rowStyle)));

table.AddColumn(
new TableColumn(
Expand All @@ -61,16 +61,16 @@ public void Write(CakeReport report)

if (includeSkippedReasonColumn)
{
table.AddRow(new Markup(item.TaskName, itemStyle),
new Markup(FormatDuration(item), itemStyle),
new Markup(item.ExecutionStatus.ToString(), itemStyle),
new Markup(item.SkippedMessage, itemStyle));
table.AddRow(new Markup(item.TaskName.EscapeMarkup(), itemStyle),
new Markup(FormatDuration(item).EscapeMarkup(), itemStyle),
new Markup(item.ExecutionStatus.ToString().EscapeMarkup(), itemStyle),
new Markup(item.SkippedMessage.EscapeMarkup(), itemStyle));
}
else
{
table.AddRow(new Markup(item.TaskName, itemStyle),
new Markup(FormatDuration(item), itemStyle),
new Markup(item.ExecutionStatus.ToString(), itemStyle));
table.AddRow(new Markup(item.TaskName.EscapeMarkup(), itemStyle),
new Markup(FormatDuration(item).EscapeMarkup(), itemStyle),
new Markup(item.ExecutionStatus.ToString().EscapeMarkup(), itemStyle));
}
}

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

var table = new Table().Border(DoubleBorder.Shared);
table.Width(100);
table.AddColumn(name);
table.AddColumn(name.EscapeMarkup());
_console.Write(new Padder(table).Padding(0, 1, 0, 0));
}

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

var table = new Table().Border(SingleBorder.Shared);
table.Width(100);
table.AddColumn(name);
table.AddColumn(name.EscapeMarkup());
_console.Write(table);
}

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

_console.WriteLine();

var table = new Table().Border(DoubleBorder.Shared);
var table = new Table()
.Border(DoubleBorder.Shared)
.BorderStyle(new Style(ConsoleColor.Gray));

table.Width(100);
table.AddColumn(name);
table.AddColumn(name.EscapeMarkup());
_console.Write(table);
}

Expand Down
31 changes: 28 additions & 3 deletions src/Cake.Cli/Infrastructure/DoubleBorder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable

using Spectre.Console;
using Spectre.Console.Rendering;
Expand All @@ -15,7 +16,10 @@ public class DoubleBorder : TableBorder
/// <summary>
/// Gets a single instance of the DoubleBorder class.
/// </summary>
public static DoubleBorder Shared { get; } = new DoubleBorder();
public static TableBorder Shared { get; } = new DoubleBorder();

/// <inheritdoc/>
public override TableBorder? SafeBorder => new Safe();

/// <summary>
/// Get information about the custom border.
Expand All @@ -26,10 +30,31 @@ public override string GetPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTop => "=",
TableBorderPart.FooterBottom => "=",
TableBorderPart.HeaderTopLeft => "═",
TableBorderPart.HeaderTop => "═",
TableBorderPart.HeaderTopRight => "═",
TableBorderPart.FooterBottomLeft => "═",
TableBorderPart.FooterBottom => "═",
TableBorderPart.FooterBottomRight => "═",
_ => string.Empty,
};
}

private sealed class Safe : TableBorder
{
public override string GetPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "=",
TableBorderPart.HeaderTop => "=",
TableBorderPart.HeaderTopRight => "=",
TableBorderPart.FooterBottomLeft => "=",
TableBorderPart.FooterBottom => "=",
TableBorderPart.FooterBottomRight => "=",
_ => string.Empty,
};
}
}
}
}
28 changes: 26 additions & 2 deletions src/Cake.Cli/Infrastructure/SingleBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class SingleBorder : TableBorder
/// </summary>
public static SingleBorder Shared { get; } = new SingleBorder();

/// <inheritdoc/>
public override TableBorder SafeBorder { get; } = new Safe();

/// <summary>
/// Get information about the custom border.
/// </summary>
Expand All @@ -26,10 +29,31 @@ public override string GetPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTop => "-",
TableBorderPart.FooterBottom => "-",
TableBorderPart.HeaderTopLeft => "─",
TableBorderPart.HeaderTop => "─",
TableBorderPart.HeaderTopRight => "─",
TableBorderPart.FooterBottomLeft => "─",
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomRight => "─",
_ => string.Empty,
};
}

private sealed class Safe : TableBorder
{
public override string GetPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "-",
TableBorderPart.HeaderTop => "-",
TableBorderPart.HeaderTopRight => "-",
TableBorderPart.FooterBottomLeft => "-",
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomRight => "-",
_ => string.Empty,
};
}
}
}
}
18 changes: 10 additions & 8 deletions src/Cake/Infrastructure/ContainerConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ public void Configure(

// Misc registrations.
registrar.RegisterType<CakeReportPrinter>().As<ICakeReportPrinter>().Singleton();
RegisterSpectreConsole(registrar, configuration);

registrar.RegisterInstance(AnsiConsole.Console).As<IAnsiConsole>().Singleton();
registrar.RegisterType<CakeConsole>().As<IConsole>().Singleton();
registrar.RegisterInstance(configuration).As<ICakeConfiguration>().Singleton();
}

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

if (useSpectreConsoleForConsoleOutput)
var useSpectre = configuration.GetValue(Constants.Settings.UseSpectreConsoleForConsoleOutput) ?? "true";
if (useSpectre.Equals("true", StringComparison.OrdinalIgnoreCase))
{
registrar.RegisterType<CakeSpectreReportPrinter>().As<ICakeReportPrinter>().Singleton();
}

registrar.RegisterType<CakeConsole>().As<IConsole>().Singleton();
registrar.RegisterInstance(configuration).As<ICakeConfiguration>().Singleton();
}
}
}
}
Loading