Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a coloured text?

Tags:

linux

d

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?

like image 221
Arlen Avatar asked Feb 05 '12 10:02

Arlen


People also ask

How do you make colored text?

Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color.

How do you make a multicolor text?

Make separate elements Another way is creating a text with separate elements by using the HTML <span> tag, which is an empty container. This means that you create a multicolor text by putting each letter in a separate element to define a different color for each letter of your text.

How do I type in red?

#ff0000 is the color code for red.

Can a Font be colored?

Color fonts, also referred to as “multicolor fonts” or “chromatic fonts,” are a relatively new font technology that allows font designers to use multiple colors within each glyph of the font.


1 Answers

The C++ constant string escape \e for 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 \033 or \x1b

Be careful however that \e[32;40m is not standard C or C++, it is the ANSI terminal escape sequence related to tty-s.

like image 143
Basile Starynkevitch Avatar answered Sep 29 '22 21:09

Basile Starynkevitch