.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Color::ANSI::Util 3pm" .TH Color::ANSI::Util 3pm "2020-06-12" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Color::ANSI::Util \- Routines for dealing with ANSI colors .SH "VERSION" .IX Header "VERSION" This document describes version 0.164 of Color::ANSI::Util (from Perl distribution Color-ANSI-Util), released on 2020\-06\-09. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use Color::ANSI::Util qw( \& ansifg \& ansibg \& ); \& \& say ansifg("f0c010"); # => "\ee[33;1m" (on 16\-color terminal) \& # => "\ee[38;5;11m" (on 256\-color terminal) \& # => "\ee[38;2;240;192;16m" (on 24\-bit\-color terminal) \& \& say ansibg("ff5f87"); # => "\ee[47m" (on 16\-color terminal) \& # => "\ee[48;5;7m" (on 256\-color terminal) \& # => "\ee[48;2;255;95;135m" (on 24\-bit\-color terminal) .Ve .PP There are a bunch of other exportable functions too, mostly for converting between \s-1RGB\s0 and \s-1ANSI\s0 color (16/256/24bit color depth). .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides routines for dealing with \s-1ANSI\s0 colors. The two main functions are \f(CW\*(C`ansifg\*(C'\fR and \f(CW\*(C`ansibg\*(C'\fR. With those functions, you can specify colors in \s-1RGB\s0 and let it output the correct \s-1ANSI\s0 color escape code according to the color depth support of the terminal (whether 16\-color, 256\-color, or 24bit). There are other functions to convert \s-1RGB\s0 to \s-1ANSI\s0 in specific color depths, or reverse functions to convert from \s-1ANSI\s0 to \s-1RGB\s0 codes. .PP Keywords: xterm, xterm\-256color, terminal .SH "BUGS/NOTES" .IX Header "BUGS/NOTES" Algorithm for finding closest indexed color from \s-1RGB\s0 color currently not very efficient. Probably can add some threshold square distance, below which we can shortcut to the final answer. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "ansi16_to_rgb" .IX Subsection "ansi16_to_rgb" Usage: .PP .Vb 1 \& ansi16_to_rgb($color) \-> color::rgb24 .Ve .PP Convert \s-1ANSI\-16\s0 color to \s-1RGB.\s0 .PP Returns 6\-hexdigit, e.g. 'ff00cc'. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::ansi16\fR .PP Return value: (color::rgb24) .SS "ansi256_to_rgb" .IX Subsection "ansi256_to_rgb" Usage: .PP .Vb 1 \& ansi256_to_rgb($color) \-> color::rgb24 .Ve .PP Convert \s-1ANSI\-256\s0 color to \s-1RGB.\s0 .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::ansi256\fR .PP Return value: (color::rgb24) .SS "rgb_to_ansi16" .IX Subsection "rgb_to_ansi16" Usage: .PP .Vb 1 \& rgb_to_ansi16($color) \-> color::ansi16 .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-16\s0 color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (color::ansi16) .SS "rgb_to_ansi16_bg_code" .IX Subsection "rgb_to_ansi16_bg_code" Usage: .PP .Vb 1 \& rgb_to_ansi16_bg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-16\s0 color escape sequence to change background color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi16_fg_code" .IX Subsection "rgb_to_ansi16_fg_code" Usage: .PP .Vb 1 \& rgb_to_ansi16_fg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-16\s0 color escape sequence to change foreground color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi24b_bg_code" .IX Subsection "rgb_to_ansi24b_bg_code" Usage: .PP .Vb 1 \& rgb_to_ansi24b_bg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\s0 24bit\-color escape sequence to change background color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi24b_fg_code" .IX Subsection "rgb_to_ansi24b_fg_code" Usage: .PP .Vb 1 \& rgb_to_ansi24b_fg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\s0 24bit\-color escape sequence to change foreground color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi256" .IX Subsection "rgb_to_ansi256" Usage: .PP .Vb 1 \& rgb_to_ansi256($color) \-> color::ansi256 .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-256\s0 color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (color::ansi256) .SS "rgb_to_ansi256_bg_code" .IX Subsection "rgb_to_ansi256_bg_code" Usage: .PP .Vb 1 \& rgb_to_ansi256_bg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-256\s0 color escape sequence to change background color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi256_fg_code" .IX Subsection "rgb_to_ansi256_fg_code" Usage: .PP .Vb 1 \& rgb_to_ansi256_fg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\-256\s0 color escape sequence to change foreground color. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi_bg_code" .IX Subsection "rgb_to_ansi_bg_code" Usage: .PP .Vb 1 \& rgb_to_ansi_bg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\s0 color escape sequence to change background color. .PP Autodetect terminal capability and can return either empty string, 16\-color, 256\-color, or 24bit\-code. .PP Which color depth used is determined by \f(CW\*(C`COLOR_DEPTH\*(C'\fR environment setting or from Term::Detect::Software if that module is available). In other words, this function automatically chooses rgb_to_ansi{24b,256,16}\fIbg\fR\fBcode()\fR. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "rgb_to_ansi_fg_code" .IX Subsection "rgb_to_ansi_fg_code" Usage: .PP .Vb 1 \& rgb_to_ansi_fg_code($color) \-> str .Ve .PP Convert \s-1RGB\s0 to \s-1ANSI\s0 color escape sequence to change foreground color. .PP Autodetect terminal capability and can return either empty string, 16\-color, 256\-color, or 24bit\-code. .PP Color depth used is determined by \f(CW\*(C`COLOR_DEPTH\*(C'\fR environment setting or from Term::Detect::Software if that module is available. In other words, this function automatically chooses rgb_to_ansi{24b,256,16}\fIfg\fR\fBcode()\fR. .PP This function is not exported by default, but exportable. .PP Arguments ('*' denotes required arguments): .IP "\(bu" 4 \&\fB\f(CB$color\fB\fR* => \fIcolor::rgb24\fR .PP Return value: (str) .SS "ansi16fg($rgb) => \s-1STR\s0" .IX Subsection "ansi16fg($rgb) => STR" Alias for \fBrgb_to_ansi16_fg_code()\fR. .SS "ansi16bg($rgb) => \s-1STR\s0" .IX Subsection "ansi16bg($rgb) => STR" Alias for \fBrgb_to_ansi16_bg_code()\fR. .SS "ansi256fg($rgb) => \s-1STR\s0" .IX Subsection "ansi256fg($rgb) => STR" Alias for \fBrgb_to_ansi256_fg_code()\fR. .SS "ansi256bg($rgb) => \s-1STR\s0" .IX Subsection "ansi256bg($rgb) => STR" Alias for \fBrgb_to_ansi256_bg_code()\fR. .SS "ansi24bfg($rgb) => \s-1STR\s0" .IX Subsection "ansi24bfg($rgb) => STR" Alias for \fBrgb_to_ansi24b_fg_code()\fR. .SS "ansi24bbg($rgb) => \s-1STR\s0" .IX Subsection "ansi24bbg($rgb) => STR" Alias for \fBrgb_to_ansi24b_bg_code()\fR. .SS "rgb_to_ansi_fg_code($rgb) => \s-1STR\s0" .IX Subsection "rgb_to_ansi_fg_code($rgb) => STR" .SS "ansifg($rgb) => \s-1STR\s0" .IX Subsection "ansifg($rgb) => STR" Alias for \fBrgb_to_ansi_fg_code()\fR. .SS "ansibg($rgb) => \s-1STR\s0" .IX Subsection "ansibg($rgb) => STR" Alias for \fBrgb_to_ansi_bg_code()\fR. .ie n .SS "ansi_reset( [ $conditional ])" .el .SS "ansi_reset( [ \f(CW$conditional\fP ])" .IX Subsection "ansi_reset( [ $conditional ])" Returns \*(L"\ee[0m\*(R", which is the \s-1ANSI\s0 escape sequence to reset color. Normally you print this sequence after you print colored text. .PP If \f(CW$conditional\fR is set to true, then \fBansi_reset()\fR will return "" if color is disabled. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" .SS "\s-1NO_COLOR\s0" .IX Subsection "NO_COLOR" Can be used to explicitly disable color. See for more details. .PP Observed by: ansi{fg,bg}. .SS "\s-1COLOR\s0 => bool" .IX Subsection "COLOR => bool" Can be used to explicitly disable color by setting it to 0. .PP Observed by: ansi{fg,bg}. .SS "\s-1COLOR_DEPTH\s0 => \s-1INT\s0" .IX Subsection "COLOR_DEPTH => INT" Can be used to explicitly set color depth instead of trying to detect appropriate color depth. .PP Observed by: ansi{fg,bg}. .SH "HOMEPAGE" .IX Header "HOMEPAGE" Please visit the project's homepage at . .SH "SOURCE" .IX Header "SOURCE" Source repository is at . .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website .PP When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. .SH "SEE ALSO" .IX Header "SEE ALSO" Term::ANSIColor .PP .SH "AUTHOR" .IX Header "AUTHOR" perlancar .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013 by perlancar@cpan.org. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.