I’m currently using the following code to output text in green to the terminal:
printf("%c[1;32mHello, world!\n", 27);
However, I want more shades of green. What’s the easiest way to accomplish this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the xterm sample 256colors2.pl script described on Rob Meerman’s site to make sure that your terminal handles 256 colors correctly. Then choose the right combination of RGB values to give you the right shade of green.
Based on that script, it looks like the color numbers are essentially an offset of a base 6 color scheme:
And for the foreground color we need to use:
And again based on the script, here’s a (perl) loop that displays the letter O in the desired color:
And here’s a sample of its output:
NOTE: Charles seems to quite a bit more about how it actually works and what you’ll need to do to verify that the the shell supports the required capabilities. My information is based strictly on observation and testing with a shell known to support 256 colors (konsole).