From 461fb48575dcacdddc8273e4735a5f3fc5775ac4 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:36:40 +0200 Subject: [PATCH] More reliable way of enablin ansi colors on netconsole Compare arguments individually instead of performing a scan over the whole command line string. --- r5dev/netconsole/netconsole.cpp | 26 +++++++++++++++++--------- r5dev/netconsole/netconsole.h | 4 ++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/r5dev/netconsole/netconsole.cpp b/r5dev/netconsole/netconsole.cpp index c178a7b8..e452f162 100644 --- a/r5dev/netconsole/netconsole.cpp +++ b/r5dev/netconsole/netconsole.cpp @@ -40,7 +40,7 @@ CNetCon::~CNetCon(void) // Purpose: WSA and NETCON systems init // Output : true on success, false otherwise //----------------------------------------------------------------------------- -bool CNetCon::Init(void) +bool CNetCon::Init(const bool bAnsiColor) { g_CoreMsgVCallback = &EngineLoggerSink; @@ -55,7 +55,7 @@ bool CNetCon::Init(void) m_bInitialized = true; - TermSetup(); + TermSetup(bAnsiColor); DevMsg(eDLL_T::NONE, "R5 TCP net console [Version %s]\n", NETCON_VERSION); static std::thread frame([this]() @@ -100,13 +100,10 @@ bool CNetCon::Shutdown(void) //----------------------------------------------------------------------------- // Purpose: terminal setup //----------------------------------------------------------------------------- -void CNetCon::TermSetup(void) +void CNetCon::TermSetup(const bool bAnsiColor) { - const char* pszCommandLine = GetCommandLineA(); - const bool bEnableColor = strstr("-ansicolor", pszCommandLine) != nullptr; - - SpdLog_Init(bEnableColor); - Console_Init(bEnableColor); + SpdLog_Init(bAnsiColor); + Console_Init(bAnsiColor); } //----------------------------------------------------------------------------- @@ -360,7 +357,18 @@ bool CNetCon::IsConnected(void) //----------------------------------------------------------------------------- int main(int argc, char* argv[]) { - if (!NetConsole()->Init()) + bool bEnableColor = false; + + for (int i = 0; i < argc; i++) + { + if (V_strcmp(argv[i], "-ansicolor") == NULL) + { + bEnableColor = true; + break; + } + } + + if (!NetConsole()->Init(bEnableColor)) { return EXIT_FAILURE; } diff --git a/r5dev/netconsole/netconsole.h b/r5dev/netconsole/netconsole.h index a4a1a96e..2a0926a6 100644 --- a/r5dev/netconsole/netconsole.h +++ b/r5dev/netconsole/netconsole.h @@ -17,10 +17,10 @@ public: CNetCon(void); ~CNetCon(void); - bool Init(void); + bool Init(const bool bAnsiColor); bool Shutdown(void); - void TermSetup(void); + void TermSetup(const bool bAnsiColor); void UserInput(void); void ClearInput(void);