# Help on pp / Wirble (irb)?

**URL:** <https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890>\
**Category:** Ruby\
**Created:** [January 22, 2007, 6:09am UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890 "2007-01-22T06:09:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 22, 2007, 6:09am UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/1 "2007-01-22T06:09:56Z")

</div>

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

[http://pablotron.org/software/wirble/](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!

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 22, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/2 "2007-01-22T14:44:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 22, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/3 "2007-01-22T20:18:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 23, 2007, 10:17am UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/4 "2007-01-23T10:17:27Z")

</div>

On 1/23/07, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 23, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/5 "2007-01-23T19:39:45Z")

</div>

On 1/23/07, Martin DeMello [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 1/23/07, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 31, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/6 "2007-01-31T12:01:54Z")

</div>

- Giles B. (removed\_email\_address@domain.invalid) wrote:

> Wirble is an enhancement to irb that gives you syntax coloring.
> 
> [http://pablotron.org/software/wirble/](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!

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [January 23, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/help-on-pp-wirble-irb/82890/7 "2007-01-23T21:20:14Z")

</div>

On 1/24/07, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
