Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions RLBotCS/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
using RLBotCS.Server.BridgeMessage;
using RLBotCS.Server.ServerMessage;

#if WINDOWS
WinTermColor.EnableVirtualTerminal();
#endif

if (args.Length > 0 && args[0] == "--version")
{
Console.WriteLine(
$"RLBotServer v5.beta.7.4\n"
+ $"Bridge {BridgeVersion.Version}\n"
+ $"@ https://www.rlbot.org & https://github.com/RLBot/core"
$"{Logging.Yellow}RLBotServer {Logging.Green}v5.beta.7.5\n"
+ $"{Logging.Yellow}Bridge {Logging.Green}{BridgeVersion.Version}{Logging.Reset}\n"
+ $"@ {Logging.LightBlue}https://www.rlbot.org{Logging.Reset} & {Logging.LightBlue}https://github.com/RLBot/core{Logging.Reset}"
);
Environment.Exit(0);
}
Expand Down
16 changes: 8 additions & 8 deletions RLBotCS/ManagerTools/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace RLBotCS.ManagerTools;

public class Logging : ILogger
{
private const string Grey = "\x1b[38;20m";
private const string LightBlue = "\x1b[94;20m";
private const string Yellow = "\x1b[33;20m";
private const string Green = "\x1b[32;20m";
private const string Red = "\x1b[31;20m";
private const string BoldRen = "\x1b[31;1m";
private const string Reset = "\x1b[0m";
public const string Grey = "\x1b[38;20m";
public const string LightBlue = "\x1b[94;20m";
public const string Yellow = "\x1b[33;20m";
public const string Green = "\x1b[32;20m";
public const string Red = "\x1b[31;20m";
public const string BoldRed = "\x1b[31;1m";
public const string Reset = "\x1b[0m";

private static readonly LogLevel LoggingLevel = Environment.GetEnvironmentVariable(
"RLBOT_LOG_LEVEL"
Expand Down Expand Up @@ -80,7 +80,7 @@ private string[] GetLogLevelColors(LogLevel logLevel) =>
LogLevel.Information => new[] { Grey, LightBlue, Grey, LightBlue },
LogLevel.Warning => new[] { Yellow, Yellow, Yellow, Yellow },
LogLevel.Error => new[] { Red, Red, Red, Red },
LogLevel.Critical => new[] { Red, BoldRen, Red, BoldRen },
LogLevel.Critical => new[] { Red, BoldRed, Red, BoldRed },
_ => new[] { Grey, Grey, Grey, Grey },
};

Expand Down
37 changes: 37 additions & 0 deletions RLBotCS/ManagerTools/WinTermColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#if WINDOWS
using System.Runtime.InteropServices;

public class WinTermColor
{
const int STD_OUTPUT_HANDLE = -11;
const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;

[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle);

[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);

[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);

public static void EnableVirtualTerminal()
{
var handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (!GetConsoleMode(handle, out uint mode))
{
// Don't use the logger here because we couldn't enable colors
Console.WriteLine("Failed to get console mode.");
return;
}

mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;

if (!SetConsoleMode(handle, mode))
{
// Don't use logger for the same reason
Console.WriteLine("Failed to set console mode.");
}
}
}
#endif