Skip to content

Commit 1eb74af

Browse files
(WIP) Add Settings_Color configuration option
1 parent f52d6a2 commit 1eb74af

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

src/Cake.Core/CakeConsole.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ public ConsoleColor BackgroundColor
3636
/// Initializes a new instance of the <see cref="CakeConsole"/> class.
3737
/// </summary>
3838
/// <param name="environment">The environment.</param>
39-
public CakeConsole(ICakeEnvironment environment)
39+
/// <param name="configuration">The configuration.</param>
40+
public CakeConsole(ICakeEnvironment environment, ICakeConfiguration configuration)
4041
{
4142
if (environment == null)
4243
{
4344
throw new ArgumentNullException(nameof(environment));
4445
}
4546

46-
_supportAnsiEscapeCodes = new Lazy<bool>(() => AnsiDetector.SupportsAnsi(environment));
47+
if (configuration is null)
48+
{
49+
throw new ArgumentNullException(nameof(configuration));
50+
}
51+
52+
_supportAnsiEscapeCodes = new Lazy<bool>(() => AnsiDetector.SupportsAnsi(environment, configuration));
4753
}
4854

4955
/// <inheritdoc/>

src/Cake.Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static class Settings
1717
public const string SkipPackageVersionCheck = "Settings_SkipPackageVersionCheck";
1818
public const string NoMonoCoersion = "Settings_NoMonoCoersion";
1919
public const string ShowProcessCommandLine = "Settings_ShowProcessCommandLine";
20+
public const string Color = "Settings_Color";
2021
}
2122

2223
public static class Paths

src/Cake.Core/Diagnostics/Console/AnsiDetector.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using System.Runtime.InteropServices;
1313
using System.Text.RegularExpressions;
14+
using Cake.Core.Configuration;
1415

1516
namespace Cake.Core.Diagnostics
1617
{
@@ -40,7 +41,7 @@ static AnsiDetector()
4041
};
4142
}
4243

43-
public static bool SupportsAnsi(ICakeEnvironment environment)
44+
public static bool SupportsAnsi(ICakeEnvironment environment, ICakeConfiguration configuration)
4445
{
4546
// Prevents the addition of ANSI color if NO_COLOR env. variable is present
4647
// https://no-color.org
@@ -49,6 +50,25 @@ public static bool SupportsAnsi(ICakeEnvironment environment)
4950
return false;
5051
}
5152

53+
if (configuration == null)
54+
{
55+
throw new ArgumentNullException(nameof(configuration));
56+
}
57+
58+
var color = configuration.GetValue(Constants.Settings.Color)?.ToLowerInvariant();
59+
60+
switch (color)
61+
{
62+
case "always":
63+
return true;
64+
65+
case "never":
66+
return false;
67+
68+
default:
69+
break;
70+
}
71+
5272
// Github action doesn't setup a correct PTY but supports ANSI.
5373
if (!string.IsNullOrWhiteSpace(environment.GetEnvironmentVariable("GITHUB_ACTION")))
5474
{

src/Cake/Commands/DefaultCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Collections.Generic;
67
using Cake.Core;
8+
using Cake.Core.Configuration;
79
using Cake.Core.Diagnostics;
810
using Cake.Features.Bootstrapping;
911
using Cake.Features.Building;
@@ -82,7 +84,7 @@ public override int Execute(CommandContext context, DefaultCommandSettings setti
8284
private static int LogException<T>(ICakeLog log, T ex) where T : Exception
8385
{
8486
log = log ?? new CakeBuildLog(
85-
new CakeConsole(new CakeEnvironment(new CakePlatform(), new CakeRuntime())));
87+
new CakeConsole(new CakeEnvironment(new CakePlatform(), new CakeRuntime()), new CakeConfiguration(new Dictionary<string, string>())));
8688

8789
if (log.Verbosity == Verbosity.Diagnostic)
8890
{

src/Cake/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Autofac;
88
using Cake.Commands;
99
using Cake.Core;
10+
using Cake.Core.Configuration;
1011
using Cake.Core.Diagnostics;
1112
using Cake.Core.IO;
1213
using Cake.Features.Bootstrapping;

0 commit comments

Comments
 (0)