Terminal control/Coloured text: Difference between revisions

(New post.)
 
(6 intermediate revisions by 3 users not shown)
Line 412:
}
</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>
[[Media:ColouredTextC++.PNG]]
 
=={{header|COBOL}}==
Line 1,015 ⟶ 1,041:
public static void main(String[] args) {
System.out.print(Color.GREEN_BACKGROUND);
System.out.printlnprint(Color.WHITE_UNDERLINED);
System.out.println("Green background with underlined white text");
System.out.println(Color.RESET);
Line 1,272 ⟶ 1,298:
 
=={{header|Locomotive Basic}}==
[[File:Cpcbasic colored text mode1.png|thumb|Graphics mode 1]]
 
[[File:Cpcbasic colored text mode0.png|thumb|Graphics mode 0]]
<syntaxhighlight lang="locobasic">10 mode 1:defint a-z
20 print "Mode 1 (4 colors):"
Line 1,532 ⟶ 1,559:
TextColor(Black);
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
uses System;
Console.ForegroundColor := ConsoleColor.Red;
Console.BackgroundColor := ConsoleColor.Yellow;
Console.WriteLine('Red on Yellow');
Console.ForegroundColor := ConsoleColor.Black;
Console.BackgroundColor := ConsoleColor.White;
Console.WriteLine('Black on White');
</syntaxhighlight>
 
=={{header|Perl}}==
Line 2,028 ⟶ 2,067:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "timer" for Timer
 
var colors = ["Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"]
62

edits