| 1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "Term::ANSIColor 3" |
| 132 | .TH Term::ANSIColor 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | Term::ANSIColor \- Color screen output using ANSI escape sequences |
| 135 | .SH "SYNOPSIS" |
| 136 | .IX Header "SYNOPSIS" |
| 137 | .Vb 8 |
| 138 | \& use Term::ANSIColor; |
| 139 | \& print color 'bold blue'; |
| 140 | \& print "This text is bold blue.\en"; |
| 141 | \& print color 'reset'; |
| 142 | \& print "This text is normal.\en"; |
| 143 | \& print colored ("Yellow on magenta.\en", 'yellow on_magenta'); |
| 144 | \& print "This text is normal.\en"; |
| 145 | \& print colored ['yellow on_magenta'], "Yellow on magenta.\en"; |
| 146 | .Ve |
| 147 | .PP |
| 148 | .Vb 2 |
| 149 | \& use Term::ANSIColor qw(uncolor); |
| 150 | \& print uncolor '01;31', "\en"; |
| 151 | .Ve |
| 152 | .PP |
| 153 | .Vb 2 |
| 154 | \& use Term::ANSIColor qw(:constants); |
| 155 | \& print BOLD, BLUE, "This text is in bold blue.\en", RESET; |
| 156 | .Ve |
| 157 | .PP |
| 158 | .Vb 4 |
| 159 | \& use Term::ANSIColor qw(:constants); |
| 160 | \& $Term::ANSIColor::AUTORESET = 1; |
| 161 | \& print BOLD BLUE "This text is in bold blue.\en"; |
| 162 | \& print "This text is normal.\en"; |
| 163 | .Ve |
| 164 | .SH "DESCRIPTION" |
| 165 | .IX Header "DESCRIPTION" |
| 166 | This module has two interfaces, one through \fIcolor()\fR and \fIcolored()\fR and the |
| 167 | other through constants. It also offers the utility function \fIuncolor()\fR, |
| 168 | which has to be explicitly imported to be used (see \s-1SYNOPSYS\s0). |
| 169 | .PP |
| 170 | \&\fIcolor()\fR takes any number of strings as arguments and considers them to be |
| 171 | space-separated lists of attributes. It then forms and returns the escape |
| 172 | sequence to set those attributes. It doesn't print it out, just returns it, |
| 173 | so you'll have to print it yourself if you want to (this is so that you can |
| 174 | save it as a string, pass it to something else, send it to a file handle, or |
| 175 | do anything else with it that you might care to). |
| 176 | .PP |
| 177 | \&\fIuncolor()\fR performs the opposite translation, turning escape sequences |
| 178 | into a list of strings. |
| 179 | .PP |
| 180 | The recognized attributes (all of which should be fairly intuitive) are |
| 181 | clear, reset, dark, bold, underline, underscore, blink, reverse, concealed, |
| 182 | black, red, green, yellow, blue, magenta, on_black, on_red, on_green, |
| 183 | on_yellow, on_blue, on_magenta, on_cyan, and on_white. Case is not |
| 184 | significant. Underline and underscore are equivalent, as are clear and |
| 185 | reset, so use whichever is the most intuitive to you. The color alone sets |
| 186 | the foreground color, and on_color sets the background color. |
| 187 | .PP |
| 188 | Note that not all attributes are supported by all terminal types, and some |
| 189 | terminals may not support any of these sequences. Dark, blink, and |
| 190 | concealed in particular are frequently not implemented. |
| 191 | .PP |
| 192 | Attributes, once set, last until they are unset (by sending the attribute |
| 193 | \&\*(L"reset\*(R"). Be careful to do this, or otherwise your attribute will last |
| 194 | after your script is done running, and people get very annoyed at having |
| 195 | their prompt and typing changed to weird colors. |
| 196 | .PP |
| 197 | As an aid to help with this, \fIcolored()\fR takes a scalar as the first argument |
| 198 | and any number of attribute strings as the second argument and returns the |
| 199 | scalar wrapped in escape codes so that the attributes will be set as |
| 200 | requested before the string and reset to normal after the string. |
| 201 | Alternately, you can pass a reference to an array as the first argument, and |
| 202 | then the contents of that array will be taken as attributes and color codes |
| 203 | and the remainder of the arguments as text to colorize. |
| 204 | .PP |
| 205 | Normally, \fIcolored()\fR just puts attribute codes at the beginning and end of |
| 206 | the string, but if you set \f(CW$Term::ANSIColor::EACHLINE\fR to some string, that |
| 207 | string will be considered the line delimiter and the attribute will be set |
| 208 | at the beginning of each line of the passed string and reset at the end of |
| 209 | each line. This is often desirable if the output is being sent to a program |
| 210 | like a pager that can be confused by attributes that span lines. Normally |
| 211 | you'll want to set \f(CW$Term::ANSIColor::EACHLINE\fR to \f(CW"\en"\fR to use this |
| 212 | feature. |
| 213 | .PP |
| 214 | Alternately, if you import \f(CW\*(C`:constants\*(C'\fR, you can use the constants \s-1CLEAR\s0, |
| 215 | \&\s-1RESET\s0, \s-1BOLD\s0, \s-1DARK\s0, \s-1UNDERLINE\s0, \s-1UNDERSCORE\s0, \s-1BLINK\s0, \s-1REVERSE\s0, \s-1CONCEALED\s0, \s-1BLACK\s0, |
| 216 | \&\s-1RED\s0, \s-1GREEN\s0, \s-1YELLOW\s0, \s-1BLUE\s0, \s-1MAGENTA\s0, \s-1ON_BLACK\s0, \s-1ON_RED\s0, \s-1ON_GREEN\s0, \s-1ON_YELLOW\s0, |
| 217 | \&\s-1ON_BLUE\s0, \s-1ON_MAGENTA\s0, \s-1ON_CYAN\s0, and \s-1ON_WHITE\s0 directly. These are the same as |
| 218 | color('attribute') and can be used if you prefer typing: |
| 219 | .PP |
| 220 | .Vb 1 |
| 221 | \& print BOLD BLUE ON_WHITE "Text\en", RESET; |
| 222 | .Ve |
| 223 | .PP |
| 224 | to |
| 225 | .PP |
| 226 | .Vb 1 |
| 227 | \& print colored ("Text\en", 'bold blue on_white'); |
| 228 | .Ve |
| 229 | .PP |
| 230 | When using the constants, if you don't want to have to remember to add the |
| 231 | \&\f(CW\*(C`, RESET\*(C'\fR at the end of each print line, you can set |
| 232 | \&\f(CW$Term::ANSIColor::AUTORESET\fR to a true value. Then, the display mode will |
| 233 | automatically be reset if there is no comma after the constant. In other |
| 234 | words, with that variable set: |
| 235 | .PP |
| 236 | .Vb 1 |
| 237 | \& print BOLD BLUE "Text\en"; |
| 238 | .Ve |
| 239 | .PP |
| 240 | will reset the display mode afterwards, whereas: |
| 241 | .PP |
| 242 | .Vb 1 |
| 243 | \& print BOLD, BLUE, "Text\en"; |
| 244 | .Ve |
| 245 | .PP |
| 246 | will not. |
| 247 | .PP |
| 248 | The subroutine interface has the advantage over the constants interface in |
| 249 | that only two subroutines are exported into your namespace, versus |
| 250 | twenty-two in the constants interface. On the flip side, the constants |
| 251 | interface has the advantage of better compile time error checking, since |
| 252 | misspelled names of colors or attributes in calls to \fIcolor()\fR and \fIcolored()\fR |
| 253 | won't be caught until runtime whereas misspelled names of constants will be |
| 254 | caught at compile time. So, polute your namespace with almost two dozen |
| 255 | subroutines that you may not even use that often, or risk a silly bug by |
| 256 | mistyping an attribute. Your choice, \s-1TMTOWTDI\s0 after all. |
| 257 | .SH "DIAGNOSTICS" |
| 258 | .IX Header "DIAGNOSTICS" |
| 259 | .ie n .IP "Bad escape sequence %s" 4 |
| 260 | .el .IP "Bad escape sequence \f(CW%s\fR" 4 |
| 261 | .IX Item "Bad escape sequence %s" |
| 262 | (F) You passed an invalid \s-1ANSI\s0 escape sequence to \fIuncolor()\fR. |
| 263 | .ie n .IP "Bareword ""%s"" not allowed while ""strict subs"" in use" 4 |
| 264 | .el .IP "Bareword ``%s'' not allowed while ``strict subs'' in use" 4 |
| 265 | .IX Item "Bareword %s not allowed while strict subs in use" |
| 266 | (F) You probably mistyped a constant color name such as: |
| 267 | .Sp |
| 268 | .Vb 1 |
| 269 | \& $Foobar = FOOBAR . "This line should be blue\en"; |
| 270 | .Ve |
| 271 | .Sp |
| 272 | or: |
| 273 | .Sp |
| 274 | .Vb 1 |
| 275 | \& @Foobar = FOOBAR, "This line should be blue\en"; |
| 276 | .Ve |
| 277 | .Sp |
| 278 | This will only show up under use strict (another good reason to run under |
| 279 | use strict). |
| 280 | .ie n .IP "Invalid attribute name %s" 4 |
| 281 | .el .IP "Invalid attribute name \f(CW%s\fR" 4 |
| 282 | .IX Item "Invalid attribute name %s" |
| 283 | (F) You passed an invalid attribute name to either \fIcolor()\fR or \fIcolored()\fR. |
| 284 | .ie n .IP "Name ""%s"" used only once: possible typo" 4 |
| 285 | .el .IP "Name ``%s'' used only once: possible typo" 4 |
| 286 | .IX Item "Name %s used only once: possible typo" |
| 287 | (W) You probably mistyped a constant color name such as: |
| 288 | .Sp |
| 289 | .Vb 1 |
| 290 | \& print FOOBAR "This text is color FOOBAR\en"; |
| 291 | .Ve |
| 292 | .Sp |
| 293 | It's probably better to always use commas after constant names in order to |
| 294 | force the next error. |
| 295 | .IP "No comma allowed after filehandle" 4 |
| 296 | .IX Item "No comma allowed after filehandle" |
| 297 | (F) You probably mistyped a constant color name such as: |
| 298 | .Sp |
| 299 | .Vb 1 |
| 300 | \& print FOOBAR, "This text is color FOOBAR\en"; |
| 301 | .Ve |
| 302 | .Sp |
| 303 | Generating this fatal compile error is one of the main advantages of using |
| 304 | the constants interface, since you'll immediately know if you mistype a |
| 305 | color name. |
| 306 | .ie n .IP "No name for escape sequence %s" 4 |
| 307 | .el .IP "No name for escape sequence \f(CW%s\fR" 4 |
| 308 | .IX Item "No name for escape sequence %s" |
| 309 | (F) The \s-1ANSI\s0 escape sequence passed to \fIuncolor()\fR contains escapes which |
| 310 | aren't recognized and can't be translated to names. |
| 311 | .SH "ENVIRONMENT" |
| 312 | .IX Header "ENVIRONMENT" |
| 313 | .IP "\s-1ANSI_COLORS_DISABLED\s0" 4 |
| 314 | .IX Item "ANSI_COLORS_DISABLED" |
| 315 | If this environment variable is set, all of the functions defined by this |
| 316 | module (\fIcolor()\fR, \fIcolored()\fR, and all of the constants not previously used in |
| 317 | the program) will not output any escape sequences and instead will just |
| 318 | return the empty string or pass through the original text as appropriate. |
| 319 | This is intended to support easy use of scripts using this module on |
| 320 | platforms that don't support \s-1ANSI\s0 escape sequences. |
| 321 | .Sp |
| 322 | For it to have its proper effect, this environment variable must be set |
| 323 | before any color constants are used in the program. |
| 324 | .SH "RESTRICTIONS" |
| 325 | .IX Header "RESTRICTIONS" |
| 326 | It would be nice if one could leave off the commas around the constants |
| 327 | entirely and just say: |
| 328 | .PP |
| 329 | .Vb 1 |
| 330 | \& print BOLD BLUE ON_WHITE "Text\en" RESET; |
| 331 | .Ve |
| 332 | .PP |
| 333 | but the syntax of Perl doesn't allow this. You need a comma after the |
| 334 | string. (Of course, you may consider it a bug that commas between all the |
| 335 | constants aren't required, in which case you may feel free to insert commas |
| 336 | unless you're using \f(CW$Term::ANSIColor::AUTORESET\fR.) |
| 337 | .PP |
| 338 | For easier debuging, you may prefer to always use the commas when not |
| 339 | setting \f(CW$Term::ANSIColor::AUTORESET\fR so that you'll get a fatal compile error |
| 340 | rather than a warning. |
| 341 | .SH "NOTES" |
| 342 | .IX Header "NOTES" |
| 343 | The codes generated by this module are standard terminal control codes, |
| 344 | complying with \s-1ECMA\-48\s0 and \s-1ISO\s0 6429 (generally referred to as \*(L"\s-1ANSI\s0 color\*(R" |
| 345 | for the color codes). The non-color control codes (bold, dark, italic, |
| 346 | underline, and reverse) are part of the earlier \s-1ANSI\s0 X3.64 standard for |
| 347 | control sequences for video terminals and peripherals. |
| 348 | .PP |
| 349 | Note that not all displays are \s-1ISO\s0 6429\-compliant, or even X3.64\-compliant |
| 350 | (or are even attempting to be so). This module will not work as expected on |
| 351 | displays that do not honor these escape sequences, such as cmd.exe, 4nt.exe, |
| 352 | and command.com under either Windows \s-1NT\s0 or Windows 2000. They may just be |
| 353 | ignored, or they may display as an \s-1ESC\s0 character followed by some apparent |
| 354 | garbage. |
| 355 | .PP |
| 356 | Jean Delvare provided the following table of different common terminal |
| 357 | emulators and their support for the various attributes: |
| 358 | .PP |
| 359 | .Vb 8 |
| 360 | \& clear bold dark under blink reverse conceal |
| 361 | \& ------------------------------------------------------------------------ |
| 362 | \& xterm yes yes no yes bold yes yes |
| 363 | \& linux yes yes yes bold yes yes no |
| 364 | \& rxvt yes yes no yes bold/black yes no |
| 365 | \& dtterm yes yes yes yes reverse yes yes |
| 366 | \& teraterm yes reverse no yes rev/red yes no |
| 367 | \& aixterm kinda normal no yes no yes yes |
| 368 | .Ve |
| 369 | .PP |
| 370 | Where the entry is other than yes or no, that emulator interpret the given |
| 371 | attribute as something else instead. Note that on an aixterm, clear doesn't |
| 372 | reset colors; you have to explicitly set the colors back to what you want. |
| 373 | More entries in this table are welcome. |
| 374 | .PP |
| 375 | Note that codes 3 (italic), 6 (rapid blink), and 9 (strikethrough) are |
| 376 | specified in \s-1ANSI\s0 X3.64 and \s-1ECMA\-048\s0 but are not commonly supported by most |
| 377 | displays and emulators and therefore aren't supported by this module at the |
| 378 | present time. \s-1ECMA\-048\s0 also specifies a large number of other attributes, |
| 379 | including a sequence of attributes for font changes, Fraktur characters, |
| 380 | double\-underlining, framing, circling, and overlining. As none of these |
| 381 | attributes are widely supported or useful, they also aren't currently |
| 382 | supported by this module. |
| 383 | .SH "SEE ALSO" |
| 384 | .IX Header "SEE ALSO" |
| 385 | \&\s-1ECMA\-048\s0 is available on-line (at least at the time of this writing) at |
| 386 | <http://www.ecma.ch/ecma1/STAND/ECMA\-048.HTM>. |
| 387 | .PP |
| 388 | \&\s-1ISO\s0 6429 is available from \s-1ISO\s0 for a charge; the author of this module does |
| 389 | not own a copy of it. Since the source material for \s-1ISO\s0 6429 was \s-1ECMA\-048\s0 |
| 390 | and the latter is available for free, there seems little reason to obtain |
| 391 | the \s-1ISO\s0 standard. |
| 392 | .PP |
| 393 | The current version of this module is always available from its web site at |
| 394 | <http://www.eyrie.org/~eagle/software/ansicolor/>. It is also part of the |
| 395 | Perl core distribution as of 5.6.0. |
| 396 | .SH "AUTHORS" |
| 397 | .IX Header "AUTHORS" |
| 398 | Original idea (using constants) by Zenin, reimplemented using subs by Russ |
| 399 | Allbery <rra@stanford.edu>, and then combined with the original idea by Russ |
| 400 | with input from Zenin. Russ Allbery now maintains this module. |
| 401 | .SH "COPYRIGHT AND LICENSE" |
| 402 | .IX Header "COPYRIGHT AND LICENSE" |
| 403 | Copyright 1996, 1997, 1998, 2000, 2001, 2002 Russ Allbery <rra@stanford.edu> |
| 404 | and Zenin <zenin@bawdycaste.org>. This program is free software; you may |
| 405 | redistribute it and/or modify it under the same terms as Perl itself. |