Skip to content

Commit

Permalink
Merge pull request #110 from benpollarduk/benpollarduk-patch-1
Browse files Browse the repository at this point in the history
Benpollarduk patch 1
  • Loading branch information
benpollarduk authored Dec 4, 2024
2 parents 805a782 + cfb4934 commit fbcd84e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions NetAF.Tests/Rendering/Console/Ansi_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ public void GivenNoColorEnvironmentVariableSetToEmptyString_WhenIsColorSuppresse
}

[TestMethod]
public void GivenNoColorEnvironmentVariableSetTo0_WhenIsColorSuppressed_ThenReturnFalse()
public void GivenNoColorEnvironmentVariableSetTo0_WhenIsColorSuppressed_ThenReturnTrue()
{
Environment.SetEnvironmentVariable(Ansi.NO_COLOR, "0");

var result = Ansi.IsColorSuppressed();

Assert.IsFalse(result);
Assert.IsTrue(result);
}

[TestMethod]
public void GivenNoColorEnvironmentVariableSetToFalse_WhenIsColorSuppressed_ThenReturnFalse()
public void GivenNoColorEnvironmentVariableSetToFalse_WhenIsColorSuppressed_ThenReturnTrue()
{
Environment.SetEnvironmentVariable(Ansi.NO_COLOR, "False");

var result = Ansi.IsColorSuppressed();

Assert.IsFalse(result);
Assert.IsTrue(result);
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions NetAF/Rendering/Console/Ansi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public static class Ansi
/// <summary>
/// Determine if color is suppressed. If the NO_COLOR environment variable is present and set to anything other than '0' or 'false' this will return true.
/// </summary>
/// <returns>True if the NO_COLOR environment variable is present and set to anything other than '0' or 'false', else false.</returns>
/// <returns>True if the NO_COLOR environment variable is present and set to anything other than an empty string, else false.</returns>
public static bool IsColorSuppressed()
{
var value = Environment.GetEnvironmentVariable(NO_COLOR)?.ToLower() ?? string.Empty;

return value switch
{
"" or "0" or "false" => false,
"" => false,
_ => true,
};
}
Expand Down

0 comments on commit fbcd84e

Please sign in to comment.