Pagination in Readline

B

Bryan Richardson

Hello All,

I'm writing a Ruby command-line terminal program using Readline, and in
some cases the output from the commands ran by the user overflows the
height of the terminal. Thus, I'd like to be able to have pagination in
the program. Any ideas how to do this?

I found the following blog post
(http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby) that
describes how to to Git-style pagination in a command-line program, but
it wasn't meant for a terminal-style program. I tried switching the
suggested code around such that I could redirect STDOUT back to the
original IO and could kill the child process used to print the output,
but that didn't work either.

Any ideas on how to do pagination in Readline would be greatly
appreciated!
 
C

cldwalker

Hi Brian,
I'm writing a Ruby command-line terminal program using Readline, and in
some cases the output from the commands ran by the user overflows the
height of the terminal.  Thus, I'd like to be able to have pagination in
the program.  Any ideas how to do this?

I've written hirb, http://tagaholic.me/hirb/, which does conditional
stdout pagination
among other things. For your particular case you'd do this:

require 'hirb'
Hirb::View.enable
Hirb::View.capture_and_render { puts output }


If the output exceeds your console height, it should default to a
system pager.
If this doesn't work you may need to pass your console's width and
height explicitly to Hirb:
Hirb::View.resize(width, height)

If Hirb doesn't do exactly what you want, you can also just rip out
the pagination stuff + tweak it.


Gabriel
 
B

Bryan Richardson

[Note: parts of this message were removed to make it a legal post.]

Awesome Gabe! This worked PERFECTLY! Thank you so much for pointing out
your project!
 
C

cldwalker

[Note:  parts of this message were removed to make it a legal post.]

Awesome Gabe!  This worked PERFECTLY!  Thank you so much for pointingout
your project!

Glad it worked out :)
Gabriel
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top