How can I output different shades of green to the terminal?

I am 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 is the easiest way to accomplish this?

+3
source share
3 answers

You can use the 256colors2.pl script on Rob Meerman to make sure your terminal correctly controls 256 colors. Then choose the right combination of RGB values ​​to get the right shade of green.

Based on his script, it looks like the color numbers are essentially an offset of the base scheme 6:

COLOR = r*6^2 + g*6 + b) + 16

:

\x1b[38;5;${COLORNUM}m

, script, (perl), O :

# now the color values
for ($green = 0; $green < 6; $green++) {
    for ($red = 0; $red < 6; $red++) {
        for ($blue = 0; $blue < 6; $blue++) {
            $color = 16 + ($red * 36) + ($green * 6) + $blue;
            print "\\x1b[38;5;${color}m :\x1b[38;5;${color}m O\x1b[0m ";
            print "\n" if ($blue == 2 || $blue == 5);
        }
    }
    print "\n";
}

:

Screenshot showing color value samples

: Charles, , , , , . , , , 256 ().

+2

, . , termcap terminfo, , .

tput.

. :

tput initc 2 500 900 100
tput setaf 2

2 ( RGB 0 1000) .

, C , infocmp.

. ( )

$ infocmp -1 | grep initc
        initc=\E]P%p1%x%p2%{255}%*%{1000}%/%02x%p3%{255}%*%{1000}%/%02x%p4%{255}%*%{1000}%/%02x,
$ infocmp -1 | grep setaf
        setaf=\E[38;5;%p1%dm,

% ( ) , infocmp man. printf .

+2

Source: https://habr.com/ru/post/1745009/


All Articles