I wanted to avoid additional coding for a single line terminator, but since there is seemingly no other solution, I resorted to Console Virtual Terminal Sequences as suggested in the comments:
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <string>
static const bool enable_VT_mode(void) {
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;
}
const std::string get_terminator(void) noexcept {
if (enable_VT_mode()) return "\x1b[0K";
else return " ";
}
Then go like this:
static const std::string terminator = get_terminator();
std::cout << "\rIt's " << leisure << " time!" << terminator;
As suggested, I added WIN32_LEAN_AND_MEAN
to exclude unnecessary stuff from windows.h