我正在使用下面的方法在终端上打印彩色文本
use Term::ANSIColor;
print color("red"), "Error\n";
但我得到的输出为:
←[31mError
我还需要做什么才能以彩色或其他方式打印文本吗?
最佳答案
您使用的是 Windows 操作系统吗?来自 http://search.cpan.org/~rra/Term-ANSIColor-4.03/lib/Term/ANSIColor.pm -
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.
您的输出显示正在添加转义序列,但控制台/终端无法显示它们。
在 Term::ANSIColor 之前加载此模块可能会有所帮助: http://search.cpan.org/~jlmorel/Win32-Console-ANSI-1.10/lib/Win32/Console/ANSI.pm
另外,关于 perlmonks 的相关讨论:http://www.perlmonks.org/?node_id=429607
关于perl - 使用 perl 以彩色打印控制台日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32797678/