more documentation. README -> README.md for doc-generaters.

This commit is contained in:
Denis Knauf 2013-01-29 18:21:50 +01:00
parent 9fa27bd927
commit 5b66c9e91a
2 changed files with 15 additions and 0 deletions

1
README Symbolic link
View file

@ -0,0 +1 @@
README.md

View file

@ -1,6 +1,7 @@
module IRB module IRB
module Pager module Pager
module PagerHelper module PagerHelper
# Parses options for `IRB::Pager::pager`
def self.options opts = nil def self.options opts = nil
opts = opts.kind_of?( Hash) ? opts.dup : {} opts = opts.kind_of?( Hash) ? opts.dup : {}
stdout = opts[:stdout] || opts[:out] || $stdout stdout = opts[:stdout] || opts[:out] || $stdout
@ -11,11 +12,24 @@ module IRB
[stdout, stderr, stdin, pager, rescuing] [stdout, stderr, stdin, pager, rescuing]
end end
# Exception formatter for `IRB::Pager::pager`.
def self.exception_formatter exception def self.exception_formatter exception
["#{exception.class}: #{exception.message}", exception.backtrace.collect {|c| "\tfrom #{c}" }].join "\n" ["#{exception.class}: #{exception.message}", exception.backtrace.collect {|c| "\tfrom #{c}" }].join "\n"
end end
end end
# Starts pager (for example `less`).
# $stdin, $stderr and $stdout will be redirected to pager and your block will be called.
# On return or a raised exception, $stdin, $stderr and $stdout will be redirected to the original IOs.
# Instead of redirecting output for your block, you can inspect an object in pager.
# If pager will be exit, your program will be run like before.
#
# Possible Options:
# `opts[:stdout]`, `opts[:out]`: redirect this instead `$stdout`
# `opts[:stderr]`, `opts[:err]`: redirect this instead `$stderr`
# `opts[:stdin]`, `opts[:in]`: redirect this instead `$stdin`
# `opts[:pager]`, `opts[:less]`, `$PAGER`, `ENV['PAGER']`: use this pager instead less
# `opts[:rescuing]`, `opts[:exceptions]`, `$PAGER_RESCUE`: unless `false` or `nil` rescue exception and print it via pager, too
def self.pager obj = nil, opts = nil, &exe def self.pager obj = nil, opts = nil, &exe
if block_given? if block_given?
stdout, stderr, stdin, pager, rescuing = PagerHelper.options( opts || obj) stdout, stderr, stdin, pager, rescuing = PagerHelper.options( opts || obj)