I am writing a small Ruby script that will run in a CLI.
To improve the interface, I need to would love to add color/boldness to some elements that I output.
Is that doable? If so, and I am almost sure this is, how?
On many terminals (but not Windows), you can use an a sequence like this: "\e[#{code}m"
, where the codes are based on these tables. The codes must be separated by a semicolon if using more than one. The major codes are:
1 Bold Intensity
4 Underline
5 Slow blink
6 Fast blink
22 Normal Intensity
Foreground 3X
Background 4X
Where X is:
-----------
0 Black
1 Red
2 Green
3 Yellow
4 Blue
5 Magenta
6 Cyan
7 White
So, for example, for slowly blinking, bold green text on a blue background, you would use "\e[5;1;32;44mWOW!\e[0m"
. The \e[0m
resets everything to the terminal default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With