Fix console formatting (#295)
* Fix console virtual processing * remove sneaky using * Only set on windows
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Runtime;
|
||||
using System.Runtime.InteropServices;
|
||||
using SPTarkov.Common.Semver;
|
||||
using SPTarkov.Common.Semver.Implementations;
|
||||
using SPTarkov.DI;
|
||||
@@ -46,6 +47,8 @@ public static class Program
|
||||
|
||||
try
|
||||
{
|
||||
SetConsoleOutputMode();
|
||||
|
||||
var watermark = serviceProvider.GetService<Watermark>();
|
||||
// Initialize Watermark
|
||||
watermark?.Initialize();
|
||||
@@ -132,4 +135,38 @@ public static class Program
|
||||
var modValidator = provider.GetRequiredService<ModValidator>();
|
||||
return modValidator.ValidateAndSort(mods);
|
||||
}
|
||||
|
||||
private static void SetConsoleOutputMode()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int stdOutputHandle = -11;
|
||||
const uint enableVirtualTerminalProcessing = 0x0004;
|
||||
|
||||
var handle = GetStdHandle(stdOutputHandle);
|
||||
|
||||
if (!GetConsoleMode(handle, out var consoleMode))
|
||||
{
|
||||
throw new Exception("Unable to get console mode");
|
||||
}
|
||||
|
||||
consoleMode |= enableVirtualTerminalProcessing;
|
||||
|
||||
if (!SetConsoleMode(handle, consoleMode))
|
||||
{
|
||||
throw new Exception("Unable to set console mode");
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user