5

我正在使用此处的文档为用户打印使用消息。有没有办法打印类似于 unix 上的手册页的特定单词BOLD 。我在 Unix 上使用它。有没有办法在此处的文档中使用 Term::ANSIColor(或其他方式?)?

4

2 回答 2

9

1)您可以简单地将ANSI代码包含到heredoc中:

print <<EOD;
XXXX\033[1;30;40m YYYY\033[1;33;43m ZZZZ\033[0mRESET
EOD

2) Heredoc 对变量进行插值,因此如果您将 ANSI 颜色包含到变量中,它就可以工作。

my $v="xxxxx";
$var = "\nXXXX\033[1;30;40m YYYY\033[1;33;43mZZZZ\033[0mRESET\n";
print <<EOD;
$var
EOD

3) 在#2 的基础上,您可以通过 Term::ANSIColor 的color()方法将 ANSI 代码生成为字符串,并在 heredoc 中使用包含该字符串的变量。抱歉,没有工作示例,因为我没有安装 ANSIColor 但应该很明显。

您可能希望将特定的 ANSI 代码存储在某个特定变量中,并将实际文本放在 heredoc 中,并将 ANSI 代码变量放在那里。

于 2010-11-11T18:29:11.357 回答
5

您可以使用@{[expression]}heredoc 中的语法来评估任意代码。如果您的终端具有深色背景和浅色前景色,则此小程序的输出看起来不错:

use Term::ANSIColor;

print <<EOF;
I am using the here doc to print usage messages 
for the user. Is there a way to print @{[colored['bright_white'],'specific words']} 
BOLD similar to the man pages on unix. I am using 
this on Unix. Is there a way to use Term::ANSIColor
(or some other way?) with the here doc?
EOF
于 2010-11-12T05:50:51.277 回答