Skip to content

Commit f882ea5

Browse files
authored
Merge pull request #129 from RLBot/win-color
Force-enable colors for cmd.exe
2 parents bb45919 + 7f68b64 commit f882ea5

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

RLBotCS/Main.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
if (args.Length > 0 && args[0] == "--version")
1111
{
1212
Console.WriteLine(
13-
$"RLBotServer v5.beta.7.4\n"
13+
"RLBotServer v5.beta.7.5\n"
1414
+ $"Bridge {BridgeVersion.Version}\n"
15-
+ $"@ https://www.rlbot.org & https://github.com/RLBot/core"
15+
+ "@ https://www.rlbot.org & https://github.com/RLBot/core"
1616
);
1717
Environment.Exit(0);
1818
}
1919

20+
#if WINDOWS
21+
WinTermColor.EnableVirtualTerminal();
22+
#endif
23+
2024
var logger = Logging.GetLogger("Main");
2125

2226
int rlbotSocketsPort;

RLBotCS/ManagerTools/Logging.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Logging : ILogger
1010
private const string Yellow = "\x1b[33;20m";
1111
private const string Green = "\x1b[32;20m";
1212
private const string Red = "\x1b[31;20m";
13-
private const string BoldRen = "\x1b[31;1m";
13+
private const string BoldRed = "\x1b[31;1m";
1414
private const string Reset = "\x1b[0m";
1515

1616
private static readonly LogLevel LoggingLevel = Environment.GetEnvironmentVariable(
@@ -80,7 +80,7 @@ private string[] GetLogLevelColors(LogLevel logLevel) =>
8080
LogLevel.Information => new[] { Grey, LightBlue, Grey, LightBlue },
8181
LogLevel.Warning => new[] { Yellow, Yellow, Yellow, Yellow },
8282
LogLevel.Error => new[] { Red, Red, Red, Red },
83-
LogLevel.Critical => new[] { Red, BoldRen, Red, BoldRen },
83+
LogLevel.Critical => new[] { Red, BoldRed, Red, BoldRed },
8484
_ => new[] { Grey, Grey, Grey, Grey },
8585
};
8686

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#if WINDOWS
2+
using System.Runtime.InteropServices;
3+
4+
public class WinTermColor
5+
{
6+
const int STD_OUTPUT_HANDLE = -11;
7+
const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
8+
9+
[DllImport("kernel32.dll", SetLastError = true)]
10+
static extern IntPtr GetStdHandle(int nStdHandle);
11+
12+
[DllImport("kernel32.dll")]
13+
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
14+
15+
[DllImport("kernel32.dll")]
16+
static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
17+
18+
public static void EnableVirtualTerminal()
19+
{
20+
var handle = GetStdHandle(STD_OUTPUT_HANDLE);
21+
if (!GetConsoleMode(handle, out uint mode))
22+
{
23+
// Don't use the logger here because we couldn't enable colors
24+
Console.WriteLine("Failed to get console mode.");
25+
return;
26+
}
27+
28+
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
29+
30+
if (!SetConsoleMode(handle, mode))
31+
{
32+
// Don't use logger for the same reason
33+
Console.WriteLine("Failed to set console mode.");
34+
}
35+
}
36+
}
37+
#endif

0 commit comments

Comments
 (0)