help on pp / Wirble (irb)?

G

Giles Bowkett

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!
 
D

Devin Mullins

Giles said:
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
 
G

Giles Bowkett

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

Martin DeMello

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
 
G

Giles Bowkett

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)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.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
 
M

Martin DeMello

(irb)
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:
=> "\"hello world\"\n"

martin
 
P

Paul Duncan

--gkQsIeIyLzf1kMz9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Giles Bowkett ([email protected]) said:
Wirble is an enhancement to irb that gives you syntax coloring.
=20
http://pablotron.org/software/wirble/
=20
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!

--=20
Paul Duncan <[email protected]> pabs in #ruby-lang (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562

--gkQsIeIyLzf1kMz9
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFFwFldzdlT34LClWIRAl8zAJ44DP2trt/t7rxnAOwkcQ/FtMUJQgCggMDL
RLlgIZkQAhYbOrCc/IDzmis=
=H2ev
-----END PGP SIGNATURE-----

--gkQsIeIyLzf1kMz9--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top