Sicherung

This commit is contained in:
Maier Stephan SI
2023-01-20 16:09:00 +01:00
parent e5257d8413
commit b684704bf8
139 changed files with 95678 additions and 499 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Consolus
{
public class ConsoleHelper
{
public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static readonly Lazy<bool> _isConsoleSupportingEscapeSequences = new Lazy<bool>(IsConsoleSupportingEscapeSequencesInternal);
private static readonly Lazy<bool> _hasInteractiveConsole = new Lazy<bool>(HasInteractiveConsoleInternal);
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static bool SupportEscapeSequences => _isConsoleSupportingEscapeSequences.Value;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public static bool HasInteractiveConsole => _hasInteractiveConsole.Value;
private static bool IsConsoleSupportingEscapeSequencesInternal()
{
if (Console.IsOutputRedirected || Console.IsErrorRedirected || !HasInteractiveConsole)
{
return false;
}
if (IsWindows)
{
WindowsHelper.EnableAnsiEscapeOnWindows();
}
var left = Console.CursorLeft;
var top = Console.CursorTop;
ConsoleStyle.Reset.Render(Console.Out);
bool support = true;
if (left != Console.CursorLeft || top != Console.CursorTop)
{
support = false;
// Remove previous sequence
Console.SetCursorPosition(left, top);
Console.Write(" "); // Clear \x1b[0m = 4 characters
Console.SetCursorPosition(left, top);
}
return support;
}
private static bool HasInteractiveConsoleInternal() => IsWindows ? WindowsHelper.HasConsoleWindows() : Environment.UserInteractive;
}
}