Sha256: 9714c3434708ecba4a7df96b31190f6cd4ace049ef1591eb13a1e66d637cf033

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 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

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 lib/tty/terminal/pager/system.rb
tty-0.0.10 lib/tty/terminal/pager/system.rb