add native color code support in console output#448
add native color code support in console output#448Kipstz wants to merge 2 commits intoBeamMP:minorfrom
Conversation
Implements ^0-^f color codes and ^r/^l/^n/^m/^o formatting codes that get converted to ANSI escape sequences in TConsole::Write and TConsole::WriteRaw functions.
|
|
||
| void TConsole::Write(const std::string& str) { | ||
| auto ToWrite = GetDate() + str; | ||
| auto ToWrite = GetDate() + ConvertColorCodes(str); |
There was a problem hiding this comment.
Could this be moved to a higher level function? I'd prefer this to be part of a printColored function (in-line with print and printRaw in lua, c++ code can just call this helper) instead of applying to everything going to the console.
There was a problem hiding this comment.
That's my opinion, but I don't necessarily see the point of having several print functions. You might as well have one that handles most things. That's how it works right now: print(“\x1b[31mError: \x1b[0mSomething went wrong”). I just simplified it by doing this: print("^4Error: ^rSomething went wrong"). I think it would be overkill to have fun creating new print functions.
There was a problem hiding this comment.
I don't want server scripts to suddenly output unexpected text, however I suppose the original will still be present in the server log.
Either way, this should be something applied in the lua api handler, not for everything going to the terminal.
This PR adds native support for color codes in console output, allowing plugin developers to easily colorize their server logs and messages using simple ^X codes.
The Problem
Currently, if developers want colored console output, they need to either:
The Solution
This implementation introduces intuitive color codes inspired by classic game server conventions (similar to Cfx, FiveM, RedM):
-- Before (raw ANSI - hard to read and write)
print("\x1b[31mError: \x1b[0mSomething went wrong")
-- After (simple and intuitive)
print("^4Error: ^rSomething went wrong")
Available Codes
StrikethroughExamples
-- Colored status messages

print("^2[SUCCESS]^r Player connected")
print("^4[ERROR]^r Connection failed")
print("^6[WARNING]^r Server is full")
-- Formatted text

print("^lBold^r and ^oitalic^r text")
-- Multiple colors

print("^1Blue ^2Green ^4Red ^rNormal")
Why This Should Be Merged