[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

help on pp / Wirble (irb)?

Giles Bowkett

1/22/2007 5:09:00 AM

Wirble is an enhancement to irb that gives you syntax coloring.

http://pablotron.org/softwa...

It also loads a few gems automatically, such as pp and irb/completion;
doing this also enhances irb, obviously.

However, if you're into the syntax coloring, and you want to use pp,
too bad -- because with pp, you lose the syntax coloring. Also, there
isn't a configuration option to set pp output as the default.

I thought it'd be easy to add both these things, but it turned out
slightly harder than I thought. The core of pp is a separate library
called prettyprint.rb, and it looks as if it's written to flush
directly to a stream. As far as I can tell, it doesn't appear to have
any obvious hooks which I can use to just get the reformatted string,
bypass the whole buffer thing, and pass the string to Wirble's
colorize method.

However, I'm actually almost certain that I must be wrong about that.
The unit tests inside prettyprint.rb appear to consistently use string
comparisons, and they wouldn't be able to do that unless the output
could be extracted as a string.

I just e-mailed the author of pp and prettyprint, but if anybody out
there has a good idea where I should begin, let me know!

--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

6 Answers

Devin Mullins

1/22/2007 1:14:00 PM

0

Giles Bowkett wrote:
> As far as I can tell, it doesn't appear to have
> any obvious hooks which I can use to just get the reformatted string,
> bypass the whole buffer thing, and pass the string to Wirble's
> colorize method.
I believe it's something like Object#pretty_print_inspect. Plus, I
believe you can pass "" as a stream to PP.pp, but I'm not positive.

Devin

Giles Bowkett

1/22/2007 7:16:00 PM

0

No dice on that exact syntax, but if there are utility methods along
those lines, it should be pretty easy.

On 1/22/07, Devin Mullins <twifkak@comcast.net> wrote:
> Giles Bowkett wrote:
> > As far as I can tell, it doesn't appear to have
> > any obvious hooks which I can use to just get the reformatted string,
> > bypass the whole buffer thing, and pass the string to Wirble's
> > colorize method.
> I believe it's something like Object#pretty_print_inspect. Plus, I
> believe you can pass "" as a stream to PP.pp, but I'm not positive.
>
> Devin
>
>


--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

Martin DeMello

1/23/2007 9:17:00 AM

0

On 1/23/07, Giles Bowkett <gilesb@gmail.com> wrote:
> No dice on that exact syntax, but if there are utility methods along
> those lines, it should be pretty easy.

works for me

irb(main):010:0> b.pretty_print_inspect
=> "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

martin

Giles Bowkett

1/23/2007 6:40:00 PM

0

On 1/23/07, Martin DeMello <martindemello@gmail.com> wrote:
> On 1/23/07, Giles Bowkett <gilesb@gmail.com> wrote:
> > No dice on that exact syntax, but if there are utility methods along
> > those lines, it should be pretty easy.
>
> works for me
>
> irb(main):010:0> b.pretty_print_inspect
> => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

I see it working for arrays and hashes, but:

(irb)
>> "asdf".pretty_print_inspect
RuntimeError: pretty_print is not overridden for String
from /opt/local/lib/ruby/1.8/pp.rb:293:in `pretty_print_inspect'
from (irb):1

(rails console)
Loading development environment.
>> app.pretty_print_inspect
RuntimeError: pretty_print is not overridden for
ActionController::Integration::Session
from /opt/local/lib/ruby/1.8/pp.rb:293:in `pretty_print_inspect'
from (irb):1

--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

Martin DeMello

1/23/2007 8:20:00 PM

0

On 1/24/07, Giles Bowkett <gilesb@gmail.com> wrote:
> (irb)
> >> "asdf".pretty_print_inspect
> RuntimeError: pretty_print is not overridden for String
> from /opt/local/lib/ruby/1.8/pp.rb:293:in `pretty_print_inspect'
> from (irb):1

Okay, it's convoluted but:

>> require 'stringio'
>> require 'pp'
>> a = ""
>> b = StringIO.new(a, 'w')
>> c = "hello world"
>> PP.pp(c, b)
=> #<StringIO:0xb7c98e70>
>> a
=> "\"hello world\"\n"

martin

Paul Duncan

1/31/2007 8:55:00 AM

0

* Giles Bowkett (gilesb@gmail.com) wrote:
> Wirble is an enhancement to irb that gives you syntax coloring.
>
> http://pablotron.org/softwa...
>
> It also loads a few gems automatically, such as pp and irb/completion;
> doing this also enhances irb, obviously.

[snipped]

> I just e-mailed the author of pp and prettyprint, but if anybody out
> there has a good idea where I should begin, let me know!

Hi Giles.

PP support for Wirble is on my list of things to add for the next
release. I haven't had a lot of free time as of late, so I don't know
when I'll be able to get to my list.

Patches are always welcome, of course!

> --
> Giles Bowkett
> http://www.gilesg...
> http://gilesbowkett.bl...
> http://gilesgoatboy.bl...

--
Paul Duncan <pabs@pablotron.org> pabs in #ruby-lang (OPN IRC)
http://www.pabl... OpenPGP Key ID: 0x82C29562