如何在Perl中的doc文档中打印BOLD文本?

时间:2010-11-11 18:07:47

标签: perl text heredoc bold

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

2 个答案:

答案 0 :(得分: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代码作为字符串,并使用包含该字符串的变量。对不起,没有工作的例子,因为我没有安装ANSIColor但应该很明显。

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

答案 1 :(得分:4)

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

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