开发者

Need to color terminal's output produced with print command Term::ANSIColor

开发者 https://www.devze.com 2023-01-31 14:44 出处:网络
Here is what I have: use Term::ANSIColor; print \"Blah!\".color(\"green\"); The output is Test←[32m What am I missing开发者_如何学编程?The terminal program you are using does not support the EC

Here is what I have:

use Term::ANSIColor;
print "Blah!".color("green");

The output is

Test←[32m

What am I missing开发者_如何学编程?


The terminal program you are using does not support the ECMA-48 color escape codes. So it does not give them any special treatment, and instead outputs the characters as-is.

What you are missing: a terminal that does. xterm, libvte, putty, are just a few to name that do.


Are you on Windows? I'm fairly certain that the Windows shell isn't compliant with the color codes used by the module.

Actually, it says so right there on the module's documentation.

Note that not all displays are ISO 6429-compliant, or even X3.64-compliant (or are even attempting to be so). This module will not work as expected on displays that do not honor these escape sequences, such as cmd.exe, 4nt.exe, and command.com under either Windows NT or Windows 2000. They may just be ignored, or they may display as an ESC character followed by some apparent garbage.

EDIT: An addendum to my comment:

C:\>perl -MWin32::Console::ANSI -MTerm::ANSIColor -e "print color(\"green\"), 'test', color(\"reset\");"

Works just fine on Windows XP, Perl 5.12.1, so there's your workaround.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号