Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Term / ANSIColor.html
blob73483820db6e407bc349e6589669023d8eea31a6
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Term::ANSIColor - Color screen output using ANSI escape sequences</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Term::ANSIColor - Color screen output using ANSI escape sequences</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#diagnostics">DIAGNOSTICS</a></li>
26 <li><a href="#environment">ENVIRONMENT</a></li>
27 <li><a href="#restrictions">RESTRICTIONS</a></li>
28 <li><a href="#notes">NOTES</a></li>
29 <li><a href="#see_also">SEE ALSO</a></li>
30 <li><a href="#authors">AUTHORS</a></li>
31 <li><a href="#copyright_and_license">COPYRIGHT AND LICENSE</a></li>
32 </ul>
33 <!-- INDEX END -->
35 <hr />
36 <p>
37 </p>
38 <h1><a name="name">NAME</a></h1>
39 <p>Term::ANSIColor - Color screen output using ANSI escape sequences</p>
40 <p>
41 </p>
42 <hr />
43 <h1><a name="synopsis">SYNOPSIS</a></h1>
44 <pre>
45 use Term::ANSIColor;
46 print color 'bold blue';
47 print &quot;This text is bold blue.\n&quot;;
48 print color 'reset';
49 print &quot;This text is normal.\n&quot;;
50 print colored (&quot;Yellow on magenta.\n&quot;, 'yellow on_magenta');
51 print &quot;This text is normal.\n&quot;;
52 print colored ['yellow on_magenta'], &quot;Yellow on magenta.\n&quot;;</pre>
53 <pre>
54 use Term::ANSIColor qw(uncolor);
55 print uncolor '01;31', &quot;\n&quot;;</pre>
56 <pre>
57 use Term::ANSIColor qw(:constants);
58 print BOLD, BLUE, &quot;This text is in bold blue.\n&quot;, RESET;</pre>
59 <pre>
60 use Term::ANSIColor qw(:constants);
61 $Term::ANSIColor::AUTORESET = 1;
62 print BOLD BLUE &quot;This text is in bold blue.\n&quot;;
63 print &quot;This text is normal.\n&quot;;</pre>
64 <p>
65 </p>
66 <hr />
67 <h1><a name="description">DESCRIPTION</a></h1>
68 <p>This module has two interfaces, one through <code>color()</code> and <code>colored()</code> and the
69 other through constants. It also offers the utility function uncolor(),
70 which has to be explicitly imported to be used (see <em>SYNOPSIS</em>).</p>
71 <p><code>color()</code> takes any number of strings as arguments and considers them to be
72 space-separated lists of attributes. It then forms and returns the escape
73 sequence to set those attributes. It doesn't print it out, just returns it,
74 so you'll have to print it yourself if you want to (this is so that you can
75 save it as a string, pass it to something else, send it to a file handle, or
76 do anything else with it that you might care to).</p>
77 <p><code>uncolor()</code> performs the opposite translation, turning escape sequences
78 into a list of strings.</p>
79 <p>The recognized attributes (all of which should be fairly intuitive) are
80 clear, reset, dark, bold, underline, underscore, blink, reverse, concealed,
81 black, red, green, yellow, blue, magenta, on_black, on_red, on_green,
82 on_yellow, on_blue, on_magenta, on_cyan, and on_white. Case is not
83 significant. Underline and underscore are equivalent, as are clear and
84 reset, so use whichever is the most intuitive to you. The color alone sets
85 the foreground color, and on_color sets the background color.</p>
86 <p>Note that not all attributes are supported by all terminal types, and some
87 terminals may not support any of these sequences. Dark, blink, and
88 concealed in particular are frequently not implemented.</p>
89 <p>Attributes, once set, last until they are unset (by sending the attribute
90 ``reset''). Be careful to do this, or otherwise your attribute will last
91 after your script is done running, and people get very annoyed at having
92 their prompt and typing changed to weird colors.</p>
93 <p>As an aid to help with this, <code>colored()</code> takes a scalar as the first argument
94 and any number of attribute strings as the second argument and returns the
95 scalar wrapped in escape codes so that the attributes will be set as
96 requested before the string and reset to normal after the string.
97 Alternately, you can pass a reference to an array as the first argument, and
98 then the contents of that array will be taken as attributes and color codes
99 and the remainder of the arguments as text to colorize.</p>
100 <p>Normally, <code>colored()</code> just puts attribute codes at the beginning and end of
101 the string, but if you set $Term::ANSIColor::EACHLINE to some string, that
102 string will be considered the line delimiter and the attribute will be set
103 at the beginning of each line of the passed string and reset at the end of
104 each line. This is often desirable if the output is being sent to a program
105 like a pager that can be confused by attributes that span lines. Normally
106 you'll want to set $Term::ANSIColor::EACHLINE to <code>&quot;\n&quot;</code> to use this
107 feature.</p>
108 <p>Alternately, if you import <code>:constants</code>, you can use the constants CLEAR,
109 RESET, BOLD, DARK, UNDERLINE, UNDERSCORE, BLINK, REVERSE, CONCEALED, BLACK,
110 RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, ON_BLACK, ON_RED, ON_GREEN,
111 ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and ON_WHITE directly. These are
112 the same as <code>color('attribute')</code> and can be used if you prefer typing:</p>
113 <pre>
114 print BOLD BLUE ON_WHITE &quot;Text\n&quot;, RESET;</pre>
115 <p>to</p>
116 <pre>
117 print colored (&quot;Text\n&quot;, 'bold blue on_white');</pre>
118 <p>When using the constants, if you don't want to have to remember to add the
119 <code>, RESET</code> at the end of each print line, you can set
120 $Term::ANSIColor::AUTORESET to a true value. Then, the display mode will
121 automatically be reset if there is no comma after the constant. In other
122 words, with that variable set:</p>
123 <pre>
124 print BOLD BLUE &quot;Text\n&quot;;</pre>
125 <p>will reset the display mode afterwards, whereas:</p>
126 <pre>
127 print BOLD, BLUE, &quot;Text\n&quot;;</pre>
128 <p>will not.</p>
129 <p>The subroutine interface has the advantage over the constants interface in
130 that only two subroutines are exported into your namespace, versus
131 twenty-two in the constants interface. On the flip side, the constants
132 interface has the advantage of better compile time error checking, since
133 misspelled names of colors or attributes in calls to <code>color()</code> and <code>colored()</code>
134 won't be caught until runtime whereas misspelled names of constants will be
135 caught at compile time. So, polute your namespace with almost two dozen
136 subroutines that you may not even use that often, or risk a silly bug by
137 mistyping an attribute. Your choice, TMTOWTDI after all.</p>
139 </p>
140 <hr />
141 <h1><a name="diagnostics">DIAGNOSTICS</a></h1>
142 <dl>
143 <dt><strong><a name="item_bad_escape_sequence__25s">Bad escape sequence %s</a></strong>
145 <dd>
146 <p>(F) You passed an invalid ANSI escape sequence to uncolor().</p>
147 </dd>
148 </li>
149 <dt><strong><a name="item_bareword__22_25s_22_not_allowed_while__22strict_su">Bareword ``%s'' not allowed while ``strict subs'' in use</a></strong>
151 <dd>
152 <p>(F) You probably mistyped a constant color name such as:</p>
153 </dd>
154 <dd>
155 <pre>
156 $Foobar = FOOBAR . &quot;This line should be blue\n&quot;;</pre>
157 </dd>
158 <dd>
159 <p>or:</p>
160 </dd>
161 <dd>
162 <pre>
163 @Foobar = FOOBAR, &quot;This line should be blue\n&quot;;</pre>
164 </dd>
165 <dd>
166 <p>This will only show up under use strict (another good reason to run under
167 use strict).</p>
168 </dd>
169 </li>
170 <dt><strong><a name="item_invalid_attribute_name__25s">Invalid attribute name %s</a></strong>
172 <dd>
173 <p>(F) You passed an invalid attribute name to either <code>color()</code> or colored().</p>
174 </dd>
175 </li>
176 <dt><strong><a name="item_name__22_25s_22_used_only_once_3a_possible_typo">Name ``%s'' used only once: possible typo</a></strong>
178 <dd>
179 <p>(W) You probably mistyped a constant color name such as:</p>
180 </dd>
181 <dd>
182 <pre>
183 print FOOBAR &quot;This text is color FOOBAR\n&quot;;</pre>
184 </dd>
185 <dd>
186 <p>It's probably better to always use commas after constant names in order to
187 force the next error.</p>
188 </dd>
189 </li>
190 <dt><strong><a name="item_no_comma_allowed_after_filehandle">No comma allowed after filehandle</a></strong>
192 <dd>
193 <p>(F) You probably mistyped a constant color name such as:</p>
194 </dd>
195 <dd>
196 <pre>
197 print FOOBAR, &quot;This text is color FOOBAR\n&quot;;</pre>
198 </dd>
199 <dd>
200 <p>Generating this fatal compile error is one of the main advantages of using
201 the constants interface, since you'll immediately know if you mistype a
202 color name.</p>
203 </dd>
204 </li>
205 <dt><strong><a name="item_no_name_for_escape_sequence__25s">No name for escape sequence %s</a></strong>
207 <dd>
208 <p>(F) The ANSI escape sequence passed to <code>uncolor()</code> contains escapes which
209 aren't recognized and can't be translated to names.</p>
210 </dd>
211 </li>
212 </dl>
214 </p>
215 <hr />
216 <h1><a name="environment">ENVIRONMENT</a></h1>
217 <dl>
218 <dt><strong><a name="item_ansi_colors_disabled">ANSI_COLORS_DISABLED</a></strong>
220 <dd>
221 <p>If this environment variable is set, all of the functions defined by this
222 module (color(), colored(), and all of the constants not previously used in
223 the program) will not output any escape sequences and instead will just
224 return the empty string or pass through the original text as appropriate.
225 This is intended to support easy use of scripts using this module on
226 platforms that don't support ANSI escape sequences.</p>
227 </dd>
228 <dd>
229 <p>For it to have its proper effect, this environment variable must be set
230 before any color constants are used in the program.</p>
231 </dd>
232 </li>
233 </dl>
235 </p>
236 <hr />
237 <h1><a name="restrictions">RESTRICTIONS</a></h1>
238 <p>It would be nice if one could leave off the commas around the constants
239 entirely and just say:</p>
240 <pre>
241 print BOLD BLUE ON_WHITE &quot;Text\n&quot; RESET;</pre>
242 <p>but the syntax of Perl doesn't allow this. You need a comma after the
243 string. (Of course, you may consider it a bug that commas between all the
244 constants aren't required, in which case you may feel free to insert commas
245 unless you're using $Term::ANSIColor::AUTORESET.)</p>
246 <p>For easier debuging, you may prefer to always use the commas when not
247 setting $Term::ANSIColor::AUTORESET so that you'll get a fatal compile error
248 rather than a warning.</p>
250 </p>
251 <hr />
252 <h1><a name="notes">NOTES</a></h1>
253 <p>The codes generated by this module are standard terminal control codes,
254 complying with ECMA-48 and ISO 6429 (generally referred to as ``ANSI color''
255 for the color codes). The non-color control codes (bold, dark, italic,
256 underline, and reverse) are part of the earlier ANSI X3.64 standard for
257 control sequences for video terminals and peripherals.</p>
258 <p>Note that not all displays are ISO 6429-compliant, or even X3.64-compliant
259 (or are even attempting to be so). This module will not work as expected on
260 displays that do not honor these escape sequences, such as cmd.exe, 4nt.exe,
261 and command.com under either Windows NT or Windows 2000. They may just be
262 ignored, or they may display as an ESC character followed by some apparent
263 garbage.</p>
264 <p>Jean Delvare provided the following table of different common terminal
265 emulators and their support for the various attributes and others have helped
266 me flesh it out:</p>
267 <pre>
268 clear bold dark under blink reverse conceal
269 ------------------------------------------------------------------------
270 xterm yes yes no yes bold yes yes
271 linux yes yes yes bold yes yes no
272 rxvt yes yes no yes bold/black yes no
273 dtterm yes yes yes yes reverse yes yes
274 teraterm yes reverse no yes rev/red yes no
275 aixterm kinda normal no yes no yes yes
276 PuTTY yes color no yes no yes no
277 Windows yes no no no no yes no
278 Cygwin SSH yes yes no color color color yes
279 Mac Terminal yes yes no yes yes yes yes</pre>
280 <p>Windows is Windows telnet, Cygwin SSH is the OpenSSH implementation under
281 Cygwin on Windows NT, and Mac Terminal is the Terminal application in Mac OS
282 X. Where the entry is other than yes or no, that emulator displays the
283 given attribute as something else instead. Note that on an aixterm, clear
284 doesn't reset colors; you have to explicitly set the colors back to what you
285 want. More entries in this table are welcome.</p>
286 <p>Note that codes 3 (italic), 6 (rapid blink), and 9 (strikethrough) are
287 specified in ANSI X3.64 and ECMA-048 but are not commonly supported by most
288 displays and emulators and therefore aren't supported by this module at the
289 present time. ECMA-048 also specifies a large number of other attributes,
290 including a sequence of attributes for font changes, Fraktur characters,
291 double-underlining, framing, circling, and overlining. As none of these
292 attributes are widely supported or useful, they also aren't currently
293 supported by this module.</p>
295 </p>
296 <hr />
297 <h1><a name="see_also">SEE ALSO</a></h1>
298 <p>ECMA-048 is available on-line (at least at the time of this writing) at
299 <a href="http://www.ecma-international.org/publications/standards/ECMA-048.HTM">http://www.ecma-international.org/publications/standards/ECMA-048.HTM</a>.</p>
300 <p>ISO 6429 is available from ISO for a charge; the author of this module does
301 not own a copy of it. Since the source material for ISO 6429 was ECMA-048
302 and the latter is available for free, there seems little reason to obtain
303 the ISO standard.</p>
304 <p>The current version of this module is always available from its web site at
305 <a href="http://www.eyrie.org/~eagle/software/ansicolor/">http://www.eyrie.org/~eagle/software/ansicolor/</a>. It is also part of the
306 Perl core distribution as of 5.6.0.</p>
308 </p>
309 <hr />
310 <h1><a name="authors">AUTHORS</a></h1>
311 <p>Original idea (using constants) by Zenin, reimplemented using subs by Russ
312 Allbery &lt;<a href="mailto:rra@stanford.edu">rra@stanford.edu</a>&gt;, and then combined with the original idea by Russ
313 with input from Zenin. Russ Allbery now maintains this module.</p>
315 </p>
316 <hr />
317 <h1><a name="copyright_and_license">COPYRIGHT AND LICENSE</a></h1>
318 <p>Copyright 1996, 1997, 1998, 2000, 2001, 2002 Russ Allbery &lt;<a href="mailto:rra@stanford.edu">rra@stanford.edu</a>&gt;
319 and Zenin. This program is free software; you may redistribute it and/or
320 modify it under the same terms as Perl itself.</p>
321 <table border="0" width="100%" cellspacing="0" cellpadding="3">
322 <tr><td class="block" style="background-color: #cccccc" valign="middle">
323 <big><strong><span class="block">&nbsp;Term::ANSIColor - Color screen output using ANSI escape sequences</span></strong></big>
324 </td></tr>
325 </table>
327 </body>
329 </html>