Sha256: 633ff885e88b65b34b4136969902d064451665504d9a475e97bd1d6fb5c59dad

Contents?: true

Size: 819 Bytes

Versions: 4

Compression:

Stored size: 819 Bytes

Contents

# encoding: utf-8

module TTY
  class Terminal
    # A class responsible for paging text
    class SystemPager < Pager
      # Use system command to page output text
      #
      # @api public
      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
    end # SystemPager
  end # Terminal
end # TTY

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tty-0.1.3 lib/tty/terminal/pager/system.rb
tty-0.1.2 lib/tty/terminal/pager/system.rb
tty-0.1.1 lib/tty/terminal/pager/system.rb
tty-0.1.0 lib/tty/terminal/pager/system.rb