Browse Source

Added more proper checks for if the console doesn't support VT100 escapes

pull/11/head
Anairkoen Schno 5 years ago
parent
commit
262695a14d
2 changed files with 13 additions and 2 deletions
  1. +12
    -2
      IPA.Loader/Logging/ConsoleWindow.cs
  2. +1
    -0
      IPA.Loader/Logging/StdoutInterceptor.cs

+ 12
- 2
IPA.Loader/Logging/ConsoleWindow.cs View File

@ -15,6 +15,8 @@ namespace IPA.Logging
private static SafeFileHandle outHandle; private static SafeFileHandle outHandle;
private static SafeFileHandle inHandle; private static SafeFileHandle inHandle;
public static bool UseVTEscapes { get; private set; } = true;
internal static IntPtr OutHandle => outHandle.DangerousGetHandle(); internal static IntPtr OutHandle => outHandle.DangerousGetHandle();
internal static IntPtr InHandle => inHandle.DangerousGetHandle(); internal static IntPtr InHandle => inHandle.DangerousGetHandle();
@ -58,10 +60,18 @@ namespace IPA.Logging
{ {
mode |= EnableVTProcessing; mode |= EnableVTProcessing;
if (!SetConsoleMode(handle, mode)) if (!SetConsoleMode(handle, mode))
throw new Win32Exception(Marshal.GetLastWin32Error());
{
UseVTEscapes = false;
Console.Error.WriteLine("Could not enable VT100 escape code processing (maybe you're running an old Windows?): " +
new Win32Exception(Marshal.GetLastWin32Error()).Message);
}
} }
else else
throw new Win32Exception(Marshal.GetLastWin32Error());
{
UseVTEscapes = false;
Console.Error.WriteLine("Could not enable VT100 escape code processing (maybe you're running an old Windows?): " +
new Win32Exception(Marshal.GetLastWin32Error()).Message);
}
} }
} }


+ 1
- 0
IPA.Loader/Logging/StdoutInterceptor.cs View File

@ -53,6 +53,7 @@ namespace IPA.Logging
private static string ConsoleColorToForegroundSet(ConsoleColor col) private static string ConsoleColorToForegroundSet(ConsoleColor col)
{ {
if (!WinConsole.UseVTEscapes) return "";
string code = "0"; // reset string code = "0"; // reset
switch (col) switch (col)


Loading…
Cancel
Save