Terminal markup | ||
---|---|---|
Prev | Written by Bayou. | Next |
Although there is nothing wrong with a black and white terminal, colors
usually brightens up the window when working in it. That's why we use
have colored directories, files and a color scheme for vim.
Because of these colors we are able to recognize patterns faster which
directly means we're cleaning up stuff at a higher success rate. In this
article you'll learn the basics in coloring up your terminal and even
some text markup's.
Before the dive into the variety of colors, the color yet to print must be escaped by one of the following escape sequences:
For example, if you want to echo yellow text onto the screen you'll have to run the following command:
echo -e "\033[93m Hello \033[0m"
Keep in mind that, if you do not 'close' the color using "\033[0m", the yellow color will leak into your terminal.
In the old days, back when i looked like an alien instead of acted as one, the terminal/console had fewer colors than the computers do today. It was common to have 8 of 26 colors
Foreground: 39, 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95,
96, 97
Background: 49, 40, 41, 42, 43, 43, 45, 46, 47, 100, 101, 102, 103, 104,
105, 106, 107
The syntacs is a bit easier here:
echo -e "\033[31m Red fg \033[0m \033[46m Cyan bg \033[0m"
Any you can even mix them:
echo -e "\033[31;46m Red fg, Cyan bg \033[0m"
The 256 coloring scheme is a bit harder to get than the 16 coloring scheme. Instead of fixed numbers the value 0 (zero) to 255 (two-hundred-fifty-five) represent the foreground and background colors. To access a color here you have to give tell the terminal which color to use.
The syntax is as followed:
echo -e "\033[38;5;1m Red fg \033[0m \033[48;5;1m Red bg
\033[0m"
While i cant figure the usage of the "5" in the middle, it is needed to keep the colors working. You can mix the 256 color schemes as followed:
echo -e "\033[38;5;201;48;5;4m Pink fg, Blue bg \033[0m"
It is possible to change the terminal's contract. This can be done by
executing the following command:
echo -e "\033[?5h" # High contrast
echo -e "\033[?5l" # Low contrast
Coming up: Text markup!
Download C++ colors programPrev | Home | Next |
Index | Up | Text Markup |