Method: CommandKit::Pager#pager
- Defined in:
- lib/command_kit/pager.rb
#pager {|io| ... } ⇒ Object
Opens a pager pipe.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/command_kit/pager.rb', line 98 def pager if !stdout.tty? || @pager_command.nil? # fallback to stdout if the process does not have a terminal or we could # not find a suitable pager command. yield stdout return end io = IO.popen(@pager_command,'w') pid = io.pid begin yield io rescue Errno::EPIPE ensure io.close begin Process.waitpid(pid) rescue Errno::EPIPE, Errno::ECHILD end end end |