Module: IRB::Pager

Defined in:
lib/irb-pager.rb

Defined Under Namespace

Modules: PagerHelper

Class Method Summary collapse

Class Method Details

.pager(obj = nil, opts = nil, &exe) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/irb-pager.rb', line 19

def self.pager obj = nil, opts = nil, &exe
	if block_given?
		stdout, stderr, stdin, pager, rescuing = PagerHelper.options( opts || obj)
		pid, dupout, duperr, dupin = nil, stdout.dup, stderr.dup, stdin.dup
		IO.pipe do |inrd, inwr|
			begin
				IO.pipe do |rd, wr|
					pid = Process.fork do
						stdin.reopen rd
						wr.close
						exec *pager
					end
					stdout.reopen wr
					stderr.reopen wr
					stdin.reopen inrd
					if rescuing
						begin
							yield
						rescue Object
							stdout.puts PagerHelper.exception_formatter
						end
					else
						yield
					end
				end
			ensure
				stdout.reopen dupout
				stderr.reopen duperr
				Process.wait pid
				stdin.reopen dupin
			end
		end
	else
		pager( opts) { Kernel.p obj }
	end
end