In C++ the following code when run in the console will print the text in colour:
cout << "\e[32;40mGreenForegroundAndBlackBackgroundText" << endl;
In D I get an error:
string s = "\e[32;40mGreenForegroundAndBlackBackgroundText"; // undefined escape sequence \e
Is there any way to get this working in D?
The C++ constant string escape
\efor the escape character is a non-standard GCC extension of C for character escapes (also adopted by Clang, probably).You just need to put the octal encoding of it perhaps as
\033or\x1bBe careful however that
\e[32;40mis not standard C or C++, it is the ANSI terminal escape sequence related to tty-s.