8inline std::mutex timeMutex;
10inline void GetThreadSafeLocalTime(
const time_t& timeInput, std::tm& timeInfo)
12 std::lock_guard<std::mutex> lock(timeMutex);
13 std::tm* result = localtime(&timeInput);
14 if (result !=
nullptr)
20inline std::string GetCurrentTimeString()
22 auto now = std::chrono::system_clock::now();
23 auto inTimeT = std::chrono::system_clock::to_time_t(now);
24 auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
29 GetThreadSafeLocalTime(inTimeT, timeInfo);
32 strftime(buffer,
sizeof(buffer),
"%H:%M:%S", &timeInfo);
34 ss << buffer <<
'.' << std::setw(3) << std::setfill(
'0') <<
static_cast<int>(milliseconds.count());
39inline const char*
const ANSI_RESET =
"\033[0m";
40inline const char*
const ANSI_SAVE_CURSOR =
"\033[s";
41inline const char*
const ANSI_LOAD_CURSOR =
"\033[u";
42inline const char*
const ANSI_HIDE_CURSOR =
"\033[?25l";
43inline const char*
const ANSI_SHOW_CURSOR =
"\033[?25h";
44inline const char*
const ANSI_CLEAR_LINE =
"\033[2K";
45inline const char*
const ANSI_SCROLL_DOWN =
"\033[D";
47inline const char*
const LOG_GREEN =
"\033[92m";
48inline const char*
const LOG_BLUE =
"\033[94m";
49inline const char*
const LOG_YELLOW =
"\033[93m";
50inline const char*
const LOG_RED =
"\033[91m";
51inline const char*
const LOG_WHITE =
"\033[97m";
53template <
typename... Args>
54void Log(Args&&... args)
57 std::ofstream logFile(
"log.txt", std::ios_base::app);
58 logFile <<
"[" << GetCurrentTimeString() <<
"] ";
59 (logFile << ... << std::forward<Args>(args)) <<
'\n';
62 std::cerr << LOG_WHITE <<
"[" << GetCurrentTimeString() <<
"] ";
63 (std::cerr << ... << std::forward<Args>(args)) << ANSI_RESET <<
'\n';
66template <
typename... Args>
67void LogColor(
const char* color, Args&&... args)
70 std::ofstream logFile(
"log.txt", std::ios_base::app);
71 logFile <<
"[" << GetCurrentTimeString() <<
"] ";
72 (logFile << ... << std::forward<Args>(args)) <<
'\n';
75 std::cerr << LOG_WHITE <<
"[" << GetCurrentTimeString() <<
"] ";
77 (std::cerr << ... << std::forward<Args>(args));
78 std::cerr << ANSI_RESET <<
'\n';
81template <
typename... Args>
82void Output(Args&&... args)
84 (std::cout << ... << std::forward<Args>(args)) << ANSI_RESET <<
'\n';
87template <
typename... Args>
88void OutputColor(
const char* color, Args&&... args)
91 (std::cout << ... << std::forward<Args>(args));
92 std::cout << ANSI_RESET <<
'\n';
95template <
typename... Args>
96void OutputErr(Args&&... args)
98 (std::cerr << ... << std::forward<Args>(args)) << ANSI_RESET <<
'\n';
101template <
typename... Args>
102void OutputErrColor(
const char* color, Args&&... args)
105 (std::cerr << ... << std::forward<Args>(args));
106 std::cerr << ANSI_RESET <<
'\n';
115 __declspec(dllimport)
void* __stdcall GetStdHandle(
unsigned long);
116 __declspec(dllimport)
int __stdcall GetConsoleMode(
void*,
unsigned long*);
117 __declspec(dllimport)
int __stdcall SetConsoleMode(
void*,
unsigned long);
118 __declspec(dllimport)
int __stdcall SetConsoleTextAttribute(
void*,
unsigned short);
130 void* hOutput = GetStdHandle(-11);
131 unsigned long outMode;
132 GetConsoleMode(hOutput, &outMode);
133 SetConsoleMode(hOutput, outMode | 0x0004);
135 void* hError = GetStdHandle(-12);
136 unsigned long errMode;
137 GetConsoleMode(hError, &errMode);
138 SetConsoleMode(hError, errMode | 0x0004);
143 void* hOutput = GetStdHandle(-11);
144 unsigned long outMode;
145 GetConsoleMode(hOutput, &outMode);
146 SetConsoleMode(hOutput, outMode & ~0x0004);
148 void* hError = GetStdHandle(-12);
149 unsigned long errMode;
150 GetConsoleMode(hError, &errMode);
151 SetConsoleMode(hError, errMode & ~0x0004);