Metrics UI: Enable virtual terminal sequence processing on Windows

https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
This commit is contained in:
Jack Grigg 2018-04-18 02:57:58 +01:00
parent c5b26acad8
commit 8fa09c244a
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
1 changed files with 28 additions and 0 deletions

View File

@ -414,6 +414,30 @@ int printInitMessage()
return 2;
}
#ifdef WIN32
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
bool enableVTMode()
{
// Set output mode to handle virtual terminal sequences
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE) {
return false;
}
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode)) {
return false;
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hOut, dwMode)) {
return false;
}
return true;
}
#endif
void ThreadShowMetricsScreen()
{
// Make this thread recognisable as the metrics screen thread
@ -425,6 +449,10 @@ void ThreadShowMetricsScreen()
int64_t nRefresh = GetArg("-metricsrefreshtime", isTTY ? 1 : 600);
if (isScreen) {
#ifdef WIN32
enableVTMode();
#endif
// Clear screen
std::cout << "\e[2J";