Terminal control/Coloured text: Difference between revisions

Content added Content deleted
m (Minor code improvement.)
(New post.)
Line 410: Line 410:
Console.WriteLine("Back to normal");
Console.WriteLine("Back to normal");
Console.ReadKey();
Console.ReadKey();
}
</syntaxhighlight>

=={{header|C++}}==
Coloured text and the background colour can be set using ANSI escape codes.

For a list of these codes see: https://en.wikipedia.org/wiki/ANSI_escape_code.
There are also many useful codes given in the Java example.
<syntaxhighlight lang="c++">
#include <iostream>
int main() {
std::cout << "\033[42m";
std::cout << "\033[4;37m";
std::cout << "Green background with underlined white text" << std::endl;
std::cout << "\033[0m" << std::endl;

std::cout << "\033[0;103m";
std::cout << "\033[1;34m";
std::cout << "Bright yellow background with bold blue text" << std::endl;
std::cout << "\033[0m" << std::endl;

std::cout << "\033[46m";
std::cout << "\033[1;95m";
std::cout << "Cyan background with bold bright magenta text" << std::endl;
std::cout << "\033[0m" << std::endl;
}
}
</syntaxhighlight>
</syntaxhighlight>