Skip to content

Commit

Permalink
Fixes ANSI colours not displaying on new Win10 builds
Browse files Browse the repository at this point in the history
Apparently ANSI colours are now locked behind some weird settings, again.

Luckily the feature is still there, so we can just invoke it when Windows 10 is happening.
  • Loading branch information
Altoids1 committed Nov 3, 2023
1 parent 3127007 commit 6625368
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ static bool IsWindows10() {
RtlGetVersion(&osInfo);
return (double)osInfo.dwMajorVersion;
};
return getSysOpType() == 10.0;
if(getSysOpType() < 10.0)
return false;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(hConsole,ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
return true;
}
#endif

Expand All @@ -52,7 +56,7 @@ void Terminal::SetColor(std::ostream& stream, Color color) {
if(disableFormatting)
return;
if (CanUseANSIColors) {
stream << "\x1b[" << std::to_string(static_cast<int>(color)) << 'm';
stream << "\x1b[" + std::to_string(static_cast<int>(color)) + 'm';
return;
}
//Here lies an insane Windows 7 fallback for this
Expand Down Expand Up @@ -80,14 +84,11 @@ void Terminal::SetColor(std::ostream& stream, Color color) {
}

void Terminal::SetBold(std::ostream& stream, bool isBold) {
#ifdef _WIN32
if(!CanUseANSIColors)
return; // FIXME: Do bolding in Windows 7 emissions!
#else
if(disableFormatting)
return;
stream << "\x1b[" << (isBold ? '1' : '0') << 'm';
#endif
stream << std::string("\x1b[") + (isBold ? "1" : "0") + "m";
}

void Terminal::ClearFormatting(std::ostream& stream) {
Expand Down

0 comments on commit 6625368

Please sign in to comment.