Skip to content

Commit

Permalink
fix: Disable Escape Sequences when running on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Aug 2, 2021
1 parent bee2073 commit f85a723
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>1.3.1</VersionPrefix>
<VersionPrefix>1.3.2</VersionPrefix>
<LangVersion>latest</LangVersion>

<Authors>Mayuki Sawatari</Authors>
Expand Down
8 changes: 6 additions & 2 deletions Kurukuru/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public static bool ShouldFallback
}
}

public static bool CanAcceptEscapeSequence { get; private set; } = (Environment.OSVersion.Platform != PlatformID.Win32NT);
private static bool _canAcceptEscapeSequence = (Environment.OSVersion.Platform != PlatformID.Win32NT);
public static bool CanAcceptEscapeSequence
=> _canAcceptEscapeSequence && !IsRunningOnCI && !Console.IsOutputRedirected;

public static bool IsRunningOnCI { get; } = !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CI"));

public static bool TryEnableEscapeSequence()
{
Expand All @@ -25,7 +29,7 @@ public static bool TryEnableEscapeSequence()
{
if (PInvoke.SetConsoleMode(stdOutput, mode | PInvoke.ConsoleMode.ENABLE_VIRTUAL_TERMINAL_PROCESSING))
{
CanAcceptEscapeSequence = true;
_canAcceptEscapeSequence = true;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Kurukuru/Spinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Spinner(string text, Pattern? pattern = null, ConsoleColor? color = null,
_cancellationTokenSource = new CancellationTokenSource();
_pattern = pattern ?? DefaultPattern;
_fallbackPattern = fallbackPattern ?? DefaultPattern;
_enabled = enabled && String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CI")) && !Console.IsOutputRedirected /* isatty */;
_enabled = enabled && !ConsoleHelper.IsRunningOnCI && !Console.IsOutputRedirected /* isatty */;

Text = text;
Color = color;
Expand Down

0 comments on commit f85a723

Please sign in to comment.