Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer)

时间秒杀一切 提交于 2019-12-01 03:41:00

问题


The following Perl 5 script:

use strict;
use warnings;

use Data::Printer;
my @a = (1,2,3,4);
p @a;

gives output:

(note the blue color), whereas this Perl 6 scripts:

use Data::Printer:from<Perl5>;
my @a = 1,2,3,4;
p @a;

gives output:

[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] 4
]

but the numbers are not colored (as for the Perl 5 case above).

System information:

$ perl --version
This is perl 5, version 29, subversion 3 (v5.29.3) built for x86_64-linux
$ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler.version'
ubuntu (18.10.Cosmic.Cuttlefish)
moar (2018.11)
v2018.11

回答1:


This seems to be an issue with version 0.40 of Data::Printer which is the current version on metacpan. If I install version 0.99 from GitHub I get colors with Perl 6 also. See also this issue.

I debugged version 0.40 a little bit, and it seems like the only difference between the call to p @a from Perl 5 version versus the same call from Perl 6, is that the Perl 6 call is called in list context, so wantarray returns true for the Perl 6 call, this apparantly makes Data::Printer turn off coloring somehow.



来源:https://stackoverflow.com/questions/54601397/terminal-ansi-colors-does-not-work-with-inlineperl5-dataprinter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!