Wrote windowsSaneify to make windows interpret ansi color codes.
This commit is contained in:
@@ -201,4 +201,8 @@ namespace mcolor
|
|||||||
std::string toEscapeCode(rgbColor c, bool bg=false);
|
std::string toEscapeCode(rgbColor c, bool bg=false);
|
||||||
|
|
||||||
std::string toEscapeCode(ansiColors::Colors c);
|
std::string toEscapeCode(ansiColors::Colors c);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
void windowsSaneify();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
4
main.cpp
4
main.cpp
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
mcolor::windowsSaneify();
|
||||||
|
#endif
|
||||||
|
|
||||||
std::cout << "Hello, World!" << std::endl;
|
std::cout << "Hello, World!" << std::endl;
|
||||||
|
|
||||||
//Color c;
|
//Color c;
|
||||||
|
@@ -6,6 +6,10 @@
|
|||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mcolor
|
namespace mcolor
|
||||||
{
|
{
|
||||||
std::string toEscapeCode(rgbColor c, bool bg)
|
std::string toEscapeCode(rgbColor c, bool bg)
|
||||||
@@ -21,4 +25,26 @@ namespace mcolor
|
|||||||
// Type casting is annoying just saying, but I want to be special about this for some reason
|
// Type casting is annoying just saying, but I want to be special about this for some reason
|
||||||
return std::format("\033[{}m", static_cast<typename std::underlying_type<ansiColors::Colors>::type>(c));
|
return std::format("\033[{}m", static_cast<typename std::underlying_type<ansiColors::Colors>::type>(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
/*
|
||||||
|
* Beat Windows into submission and make it interpret ansi codes.
|
||||||
|
* Fuck you Microsoft we're doing this the right way.
|
||||||
|
* This only works on Windows 10 version 1511 and newer.
|
||||||
|
*
|
||||||
|
* This function is meant to be a helper that's used in ifdef macros to allow
|
||||||
|
* us to print ansi color codes to the terminal. It's always gonna have to tag
|
||||||
|
* along with any code that is printing the escape codes to a terminal.
|
||||||
|
*/
|
||||||
|
void windowsSaneify() {
|
||||||
|
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
DWORD consoleMode;
|
||||||
|
GetConsoleMode( handleOut, &consoleMode);
|
||||||
|
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||||
|
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
|
||||||
|
SetConsoleMode( handleOut , consoleMode );
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user