Skip to content

Commit

Permalink
Metrics UI: Enable virtual terminal sequence processing on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed May 24, 2018
1 parent 10475af commit d308a42
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";

Expand Down

0 comments on commit d308a42

Please sign in to comment.