Class: TTY::Terminal::SystemPager

Inherits:
Pager
  • Object
show all
Defined in:
lib/tty/terminal/pager/system.rb

Overview

A class responsible for paging text

Instance Attribute Summary

Attributes inherited from Pager

#enabled, #text

Instance Method Summary collapse

Methods inherited from Pager

available, available?, command, #enabled?, executables, #initialize, page

Constructor Details

This class inherits a constructor from TTY::Terminal::Pager

Instance Method Details

#pageObject

Use system command to page output text



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tty/terminal/pager/system.rb', line 12

def page
  read_io, write_io = IO.pipe

  if Kernel.fork
    # parent process
    TTY.shell.input.reopen(read_io)
    read_io.close
    write_io.close

    # Wait until we have input before we start the pager
    Kernel.select [TTY.shell.stdin]

    begin
      Kernel.exec(Pager.command)
    rescue
      Kernel.exec "/bin/sh", "-c", command
    end
  else
    # child process
    write_io.write(text)
    write_io.close
    read_io.close
  end
end