I want to output many different foreground colors with one statement.
PS C:\\> Write-Host \"Red\" -ForegroundColor Red
Red
This output i
If you are in my situation, I've found a plain vanilla way from microsoft docs to set console mode. So here is an easy way to start and end 256 colors ansi console support in both cmd and powershell:
// https://docs.microsoft.com/en-us/windows/console/setconsolemode
#include <Windows.h>
#include <iostream>
struct console_data {
HANDLE hstdin;
DWORD mode;
DWORD start()
{
hstdin = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(hstdin, &mode);
if (!SetConsoleMode(hstdin, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) {
DWORD E = GetLastError();
std::cout << " Error #" << E << "in:" __FUNCTION__ "\n";
return GetLastError();
}
std::cout << "\033[1;14mReady.\e[0m\n";
return 0;
}
void end()
{
SetConsoleMode(hstdin, mode);
}
~console_data() {
end();
}
//...
}RTConsole;
//...
int main()
{
//...
RTConsole.start();
std::cout << "\033[38;5;192m Should be 'Orange'\n";
RTConsole.end();
return 0;
}
https://docs.microsoft.com/en-us/windows/console/setconsolemode
Note: I did not find how to get 256 colors support into VS Code's poswershell extension.