Skip Menu |

This queue is for tickets about the Devel-REPL CPAN distribution.

Report information
The Basics
Id: 59429
Status: open
Priority: 0/
Queue: Devel-REPL

People
Owner: Nobody in particular
Requestors: csjewell [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.003011
Fixed in: (no value)



Subject: Making colorization work correctly on Windows.
Attached patches specify (hopefully the correct) git repository to branch off of, and load a module that allows Term::ANSIColor to work within Win32 console (command prompt) windows.
Subject: 0002-Add-repository-line-to-Makefile.PL.patch
From 839eca73406a4df730f218231f5c810262a5886b Mon Sep 17 00:00:00 2001 From: Curtis Jewell <perl@csjewell.fastmail.us> Date: Thu, 15 Jul 2010 18:07:06 -0600 Subject: [PATCH 2/2] Add 'repository' line to Makefile.PL. This also adds it to the META.yml and to search.cpan.org - which makes for a lower barrier to entry. --- Makefile.PL | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 4dda752..d5dc95c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -71,6 +71,8 @@ feature 'Refresh plugin - automatically reload libraries with Module::Refresh', test_requires 'Test::More'; +repository 'git://git.shadowcat.co.uk/p5sagit/Devel-REPL.git'; + auto_install; WriteAll; -- 1.6.5.1.1367.gcd48
Subject: 0001-Add-module-that-colorizes-Win32-console-windows-when.patch
From 042df9e7103ce566bc3de74e14cc94ef15dec7ef Mon Sep 17 00:00:00 2001 From: Curtis Jewell <perl@csjewell.fastmail.us> Date: Thu, 15 Jul 2010 18:05:02 -0600 Subject: [PATCH 1/2] Add module that colorizes Win32 console windows when needed. --- Makefile.PL | 1 + lib/Devel/REPL/Plugin/Colors.pm | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index e8837ba..4dda752 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -22,6 +22,7 @@ requires 'File::HomeDir'; requires 'Task::Weaken'; requires 'B::Concise'; requires 'Term::ANSIColor'; +requires 'Win32::Console::ANSI' if $^O =~ /Win32/; requires 'Devel::Peek'; feature 'Completion plugin - extensible tab completion', diff --git a/lib/Devel/REPL/Plugin/Colors.pm b/lib/Devel/REPL/Plugin/Colors.pm index e3d0725..3a1ade3 100644 --- a/lib/Devel/REPL/Plugin/Colors.pm +++ b/lib/Devel/REPL/Plugin/Colors.pm @@ -1,6 +1,7 @@ package Devel::REPL::Plugin::Colors; use Devel::REPL::Plugin; +require Win32::Console::ANSI if $^O =~ /Win32/; use Term::ANSIColor; use namespace::clean -except => [ 'meta' ]; -- 1.6.5.1.1367.gcd48
I tried applying the patches to the Devel::REPL repo and they went in ok but I was not able to get the Colors plugin to work so I backed out the changes pending further investigation by someone who knows more about these patches.
I tried again to get win32 colorization to work
using the Win32::Console::ANSI module in
SPP 5.16.0.  No success.

Has anyone been able to get this to work?
It would be nice to have.  FWIW, I do get color
from a syntax error but the routine interaction
in the re.pl shell and the Default profile yields
stuff like this:

C:\chm\strawberry\v516\perl\site\lib\Devel\REPL\Plugin>re

$ print "hello\n"
hello
←[32m1←[0m
$ print color('bright blue')
←[1;31mRuntime error: Undefined subroutine &Devel::REPL::Plugin::Packages::DefaultScratchpad::color called at (eval 397) line 5.
←[0m
$ use Term::ANSIColor
←[32m←[0m
$ print color('bright blue')
←[1;31mRuntime error: Invalid attribute name bright at (eval 406) line 5.
←[0m
$ print color('dark blue')
←[32m1←[0m
$ ls
←[1;31mCompile error: Bareword "ls" not allowed while "strict subs" in use at (eval 408) line 5.
←[0m
$ exit
←[2;34m

Where you can see that the ANSI escape sequences are not being
translated by Win32::Console::ANSI.

--Chris

I dug into the problem. The reason why csjewell's patch is not working is Term::Readline problem. REPL.pm gets output filehandle from has 'term' => ( is => 'rw', required => 1, default => sub { Term::ReadLine->new('Perl REPL') } ); ... has 'out_fh' => ( is => 'rw', required => 1, lazy => 1, default => sub { shift->term->OUT || \*STDOUT; } ); and print results in sub print function finally. you can see colored output after inserting the following line in print sub. sub print { my ($self, @ret) = @_; my $fh = $self->out_fh; no warnings 'uninitialized'; print "@ret\n"; # <---- can see colored output. print $fh "@ret"; print $fh "\n" if $self->term->ReadLine =~ /Gnu/; } It seems that output filehandle got from Term::Readline can't properly handle Win32::Console::ANSI's ansi codes. Need fix out_fh attribute or Term::Readline ? I don't know how to fix it. :| On Sat Jul 07 15:19:49 2012, CHM wrote: Show quoted text
> I tried again to get win32 colorization to work > using the Win32::Console::ANSI module in > SPP 5.16.0. No success. > > Has anyone been able to get this to work? > It would be nice to have. FWIW, I do get color > from a syntax error but the routine interaction > in the re.pl shell and the Default profile yields > stuff like this: > > C:\chm\strawberry\v516\perl\site\lib\Devel\REPL\Plugin>re > > $ print "hello\n" > hello > ←[32m1←[0m > $ print color('bright blue') > ←[1;31mRuntime error: Undefined subroutine > &Devel::REPL::Plugin::Packages::DefaultScratchpad::color called at > (eval 397) > line 5. > ←[0m > $ use Term::ANSIColor > ←[32m←[0m > $ print color('bright blue') > ←[1;31mRuntime error: Invalid attribute name bright at (eval 406) line > 5. > ←[0m > $ print color('dark blue') > ←[32m1←[0m > $ ls > ←[1;31mCompile error: Bareword "ls" not allowed while "strict subs" in > use at > (eval 408) line 5. > ←[0m > $ exit > ←[2;34m > > Where you can see that the ANSI escape sequences are not being > translated by Win32::Console::ANSI. > > --Chris
FYI *Term::ReadLine RT ticket https://rt.cpan.org/Public/Bug/Display.html?id=83784 On Sat Mar 02 03:44:22 2013, AERO wrote: Show quoted text
> I dug into the problem. > > The reason why csjewell's patch is not working is Term::Readline problem. > > REPL.pm gets output filehandle from > > has 'term' => ( > is => 'rw', required => 1, > default => sub { Term::ReadLine->new('Perl REPL') } > ); > ... > has 'out_fh' => ( > is => 'rw', required => 1, lazy => 1, > default => sub { shift->term->OUT || \*STDOUT; } > ); > > > and print results in sub print function finally. > > you can see colored output after inserting the following line in print
sub. Show quoted text
> > sub print { > my ($self, @ret) = @_; > my $fh = $self->out_fh; > no warnings 'uninitialized'; > print "@ret\n"; # <---- can see colored output. > print $fh "@ret"; > > print $fh "\n" if $self->term->ReadLine =~ /Gnu/; > } > > It seems that output filehandle got from Term::Readline can't properly > handle Win32::Console::ANSI's ansi codes. > > > Need fix out_fh attribute or Term::Readline ? > I don't know how to fix it. :| > > On Sat Jul 07 15:19:49 2012, CHM wrote:
> > I tried again to get win32 colorization to work > > using the Win32::Console::ANSI module in > > SPP 5.16.0. No success. > > > > Has anyone been able to get this to work? > > It would be nice to have. FWIW, I do get color > > from a syntax error but the routine interaction > > in the re.pl shell and the Default profile yields > > stuff like this: > > > > C:\chm\strawberry\v516\perl\site\lib\Devel\REPL\Plugin>re > > > > $ print "hello\n" > > hello > > ←[32m1←[0m > > $ print color('bright blue') > > ←[1;31mRuntime error: Undefined subroutine > > &Devel::REPL::Plugin::Packages::DefaultScratchpad::color called at > > (eval 397) > > line 5. > > ←[0m > > $ use Term::ANSIColor > > ←[32m←[0m > > $ print color('bright blue') > > ←[1;31mRuntime error: Invalid attribute name bright at (eval 406) line > > 5. > > ←[0m > > $ print color('dark blue') > > ←[32m1←[0m > > $ ls > > ←[1;31mCompile error: Bareword "ls" not allowed while "strict subs" in > > use at > > (eval 408) line 5. > > ←[0m > > $ exit > > ←[2;34m > > > > Where you can see that the ANSI escape sequences are not being > > translated by Win32::Console::ANSI. > > > > --Chris
> >