pageme: A gem for invoking pagers from ruby

I got annoyed with being unable to page large amounts of data inside IRB, so I thought “Surely there must be a gem for this”. It turns out there isn’t. I mean there are extended versions of IRB that satisfy this specific need, but there’s no gem for “pipe this output to a pager”. Various gems do their own paging in various ways.

So I wrote one. It’s got a pretty simple API, but it seems to nicely do what I want: You can page strings to it, you can page from a block, you can redirect STDOUT and STDERR to a pager, etc.

It works on JRuby, which is apparently novel. Apparently no one has actually got that to work properly before. I can’t take too much credit for it – I merely observed that the posix-spawn gem works well enough in JRuby to launch a pager on a file then applied sufficient creative evil to bootstrap that into paging arbitrary things. The way it works is rather a hack – instead of piping directly to the less process it uses a unix domain socket to communicate with a netcat process piped into it. Really. And yes, a FIFO would be better, but for one reason or another I had a hell of a time getting it to work.

Charles Nutter has got an experimental version working with Java 7’s process builder which I hope to be able to incorporate, but I haven’t yet and will still have to leave a fall back approach in place for dealing with Java pre 7.

So far my cross-platform testing has been extremely thin on the ground. I’ve tried on MRI 1.8.7, MRI 1.9.2, JRuby 1.6.2 and JRuby-head, but only on my (linux) laptop. It probably doesn’t work entirely correctly under OSX (I’d expect the non JRuby version to, as it doesn’t do anything terribly controversial, but it might not). There’s no chance at all that it will work under windows.

My current plans which would allow me to take it to 1.0 are basically to get anyone who is interested in using it to do the cross platform testing for me, see if anything jumps out at me as wrong with the API, and figure out a way to do automated testing of this (I haven’t yet, because it’s by its nature mostly about interaction. I can definitely test some bits of it though).

Patches and suggestions welcome.

This entry was posted in programming on by .