Class: Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/pager.rb

Constant Summary collapse

PAGER_CMD =
"less"
PAGER_ENV =
{ "LESS" => "FRX", "LV" => "-c" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = {}, stdout = $stdout, stderr = $stderr) ⇒ Pager

Returns a new instance of Pager.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pager.rb', line 7

def initialize(env = {}, stdout = $stdout, stderr = $stderr)
  env = PAGER_ENV.merge(env)
  cmd = env["GIT_PAGER"] || env["PAGER"] || PAGER_CMD

  reader, writer = IO.pipe
  options = { :in => reader, :out => stdout, :err => stderr }

  @pid   = Process.spawn(env, cmd, options)
  @input = writer

  reader.close
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/pager.rb', line 5

def input
  @input
end

Instance Method Details

#waitObject



20
21
22
23
# File 'lib/pager.rb', line 20

def wait
  Process.waitpid(@pid) if @pid
  @pid = nil
end