Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

raku

The following Perl 5 script:

use strict;
use warnings;

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

gives output:

enter image description here

(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
like image 665
Håkon Hægland Avatar asked Oct 16 '22 07:10

Håkon Hægland


1 Answers

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.

like image 118
Håkon Hægland Avatar answered Nov 15 '22 08:11

Håkon Hægland