mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-29 11:50:56 +00:00
Add color to console output
This commit is contained in:
parent
657cf3bf33
commit
c1a6c3aa87
1 changed files with 21 additions and 1 deletions
|
@ -31,10 +31,10 @@
|
|||
#include "nel/misc/mutex.h"
|
||||
#include "nel/misc/report.h"
|
||||
#include "nel/misc/system_utils.h"
|
||||
#include "nel/misc/variable.h"
|
||||
|
||||
#include "nel/misc/debug.h"
|
||||
|
||||
|
||||
#ifdef NL_OS_WINDOWS
|
||||
// these defines is for IsDebuggerPresent(). it'll not compile on windows 95
|
||||
// just comment this and the IsDebuggerPresent to compile on windows 95
|
||||
|
@ -57,6 +57,8 @@ using namespace std;
|
|||
namespace NLMISC
|
||||
{
|
||||
|
||||
CVariable<bool> StdDisplayerColor("nel", "StdDisplayerColor", "Enable colors in std displayer", true, 0, true);
|
||||
|
||||
static const char *LogTypeToString[][8] = {
|
||||
{ "", "ERR", "WRN", "INF", "DBG", "STT", "AST", "UKN" },
|
||||
{ "", "Error", "Warning", "Information", "Debug", "Statistic", "Assert", "Unknown" },
|
||||
|
@ -139,9 +141,20 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
|
|||
bool needSpace = false;
|
||||
//stringstream ss;
|
||||
string str;
|
||||
#ifdef NL_OS_UNIX
|
||||
bool colorSet = false;
|
||||
#endif
|
||||
|
||||
if (args.LogType != CLog::LOG_NO)
|
||||
{
|
||||
#ifdef NL_OS_UNIX
|
||||
if (StdDisplayerColor.get())
|
||||
{
|
||||
if (args.LogType == CLog::LOG_ERROR || args.LogType == CLog::LOG_ASSERT) { str += "\e[0;30m\e[41m"; colorSet = true; } // black text, red background
|
||||
else if (args.LogType == CLog::LOG_WARNING) { str += "\e[0;91m"; colorSet = true; } // bright red text
|
||||
else if (args.LogType == CLog::LOG_DEBUG) { str += "\e[0;34m"; colorSet = true; } // blue text
|
||||
}
|
||||
#endif
|
||||
//ss << logTypeToString(args.LogType);
|
||||
str += logTypeToString(args.LogType);
|
||||
needSpace = true;
|
||||
|
@ -218,6 +231,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
|
|||
}
|
||||
#endif // NL_OS_WINDOWS
|
||||
|
||||
#ifdef NL_OS_UNIX
|
||||
if (colorSet)
|
||||
{
|
||||
str += "\e[0m";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Printf ?
|
||||
if (consoleMode)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue