Help on pp / Wirble (irb)?

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

http://pablotron.org/software/wirble/

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 B. 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

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

On 1/23/07, Giles B. [email protected] 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

On 1/23/07, Martin DeMello [email protected] wrote:

On 1/23/07, Giles B. [email protected] 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

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

http://pablotron.org/software/wirble/

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!

On 1/24/07, Giles B. [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs