Enabled ANSI color support in Windows console for retroshare-service

This commit is contained in:
thunder2 2023-11-06 23:00:06 +01:00
parent cd81d69357
commit eb7e2ec8e6

View File

@ -111,6 +111,33 @@ int main(int argc, char* argv[])
signal(SIGBREAK, signalHandler); signal(SIGBREAK, signalHandler);
#endif // ifdef SIGBREAK #endif // ifdef SIGBREAK
#ifdef WINDOWS_SYS
// Enable ANSI color support in Windows console
{
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4
#endif
HANDLE hStdin = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdin) {
DWORD consoleMode;
if (GetConsoleMode(hStdin, &consoleMode)) {
if ((consoleMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0) {
if (SetConsoleMode(hStdin, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) {
std::cout << "Enabled ANSI color support in console" << std::endl;
} else {
RsErr() << "Error getting console mode" << std::endl;
}
}
} else {
RsErr() << "Error getting console mode" << std::endl;
}
} else {
RsErr() << "Error getting stdin handle" << std::endl;
}
}
#endif
RsInfo() << "\n" << RsInfo() << "\n" <<
"+================================================================+\n" "+================================================================+\n"
"| o---o o |\n" "| o---o o |\n"