Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rubygem for invoking pagers
Ruby
branch: with_fifo

This branch is 4 commits ahead, 24 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
Gemfile
LICENSE
README.md
Rakefile
pageme.gemspec

README.md

PageMe

PageMe is a trivial rubygem for invoking a pager on application data.

Usage

Include PageMe for use:

include PageMe

Paging a string:

page "some long string\nwhich spans many lines"

Paging an enumerable will page each element to its own line:

page (1..10000)

You can page multiple things at once

page "these", "strings", "will", "each", "go", "on", "their", "own", "line"

You can also page to a block

page do |o|
  10000.times do |i|
    o.puts i
  end
end

You can combine the different formats, which will page the arguments then the block

page "this is the first string" do |o|
  10000.times do |i|
    o.puts i
  end
end

It's ok for the blocks to throw exceptions

page{ raise "Denied!" }

Their results will be printed to the pager.

If you're passing multiple arguments and one of them raises an error then no further data will be paged

page lambda{raise "Denied!"}, "this line will never be printed"

If you want to page the results of the block first you can pass it as an argument

page "This line is printed first", lambda{ |o| 10.times{|i| o.puts i } }, "I just printed a bunch of lines"

You can page to a file either by passing its file name to page_file

page_file "path/to/some/file"

or by passing an IO object

page File.open("path/to/some/file")

but the above example is bad because it won't close the file handle.

You can configure the pager being invoked:

self.pager = "more"
page %w{I hate fun}

You can also just disable paging if you want to print to STDOUT:

self.disable_paging
page %w{this will go to STDOUT as if it were the pager}

This is the default if STDOUT is not a tty.

You can of course enable it again:

self.enable_paging
page %w{this will go to a pager as normal}

TODO

Doesn't work on JRuby at the moment due to posix/spawn not correctly handling closing file handles under JRuby yet. It will work as soon as that does.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.