in reply to In Term::ANSIColor grey color is present or not.

Keep in mind, this is sort of what's happening in the background. This function takes a three-digit hexadecimal number as the first argument. The first digit is the style, second digit is the bg color and the third digit is the text color. The bg color goes from 0 to 7, I think. Then the text color goes from 0 to F. cprintf(0x07F, 'Hello World') will print on grey background using white letters. Why do you insist using color names instead of numbers?

# # Usage: cprintf(COLOR, TEXT, [ARGS]) # sub cprintf { @_ > 1 or return; my $E = shift; my $A = ($E & 0xF00) >> 8; # Get font style my $B = ($E & 0x0F0) >> 4; # Get background color my $C = ($E & 0x00F); # Get text color # Linux/OSX cprintf solution using ANSI codes: $E = '2648375vnrptosqu'; # Color code translation table $E = "\x1B[" . (vec($E, $C, 8) - 20) . "m\x1B[" . (vec($E, $B, 8) - +10) . 'm'; if ($A & 1) { $E .= "\x1B[05m"; } # BLINKING if ($A & 2) { $E .= "\x1B[04m"; } # UNDERLINE if ($A & 4) { $E .= "\x1B[03m"; } # ITALIC if ($A & 8) { $E .= "\x1B[01m"; } # BOLD print $E; # Set color printf(@_); print "\x1B[0m"; # Reset color return; }

Replies are listed 'Best First'.
Re^2: In Term::ANSIColor grey color is present or not.
by soonix (Chancellor) on Apr 02, 2022 at 08:42 UTC
    On a system with 8 colors (don't know how seldom they are, but probably not extinct) your example would depict what I know as "east frisian war flag (white eagle on white background)". And there seems to be difficulty to programmatically find out how many colors are available (or at least distinguish between 8 and 16).