NAME Color::ANSI::Util - Routines for dealing with ANSI colors VERSION version 0.01 SYNOPSIS use Color::ANSI::Util qw( ansi16_to_rgb ansi256_to_rgb rgb_to_ansi16 rgb_to_ansi256 ); # convert ANSI-16 color to RGB say ansi16_to_rgb("31"); # => "800000" (red) say ansi16_to_rgb("red"); # => "800000" (ditto) say ansi16_to_rgb("31;1"); # => "ff0000" (red bold) say ansi16_to_rgb("bold red"); # => "ff0000" (ditto) # convert RGB to ANSI-16 say ansi16_to_rgb("ac0405"); # => "31" (closest to red) say ansi16_to_rgb("f01010"); # => "31;1" (closest to bold red) # convert ANSI-256 color to RGB say ansi256_to_rgb(204); # => "ff5f87" # convert RGB to ANSI-256 color say rgb_to_ansi256("ff5f88"); # => 204 (closest) DESCRIPTION This module provides routines for dealing with ANSI colors. Keywords: xterm, xterm-256color, terminal FUNCTIONS ansi16_to_rgb($color) => STR Convert ANSI-16 color to RGB. $color can be 30-37, or "30;1" to "37;1" (for bold), or color names "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white" with "bold" to indicate bold/bright. rgb_to_ansi16($color) => STR Convert RGB to ANSI-16 color. $color is 6-hexdigit RGB color like "abcdef". Will pick the closest color. Return color in the form that is convenient for printing ANSI escape code to set foreground color, e.g. "31", "31;1" (when printed as color code, "\e[31m" or "\e[31;1m"). To set background color, add decimal 10 value to the first number, e.g. "\e[41m" or "\e[41;1m". ansi256_to_rgb($color) => STR Convert ANSI-256 color to RGB. $color is a number from 0-255. rgb_to_ansi256($color) => STR Convert RGB to ANSI-256 color. $color is 6-hexdigit RGB color like "abcdef". Will pick the closest color. Return number between 0-255. Note: to print ANSI escape code to set foreground color, use: "\e[38;5;m" and to set background color: "\e[48;5;m". BTW, ANSI code to set RGB foreground color (supported by Konsole/Yakuake): "\e[38;2;;;m" and to set RGB background color: "\e[48;2;;;m", where R, G, B are decimal values. BUGS/NOTES Algorithm currently not very efficient. SEE ALSO Term::ANSIColor http://en.wikipedia.org/wiki/ANSI_escape_code AUTHOR Steven Haryanto COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Steven Haryanto. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.