Sha256: 9cefc36be6b8ccc6eb1f6a3d9076daa5a63a2df13956bb6c2e56c9f303feadf4

Contents?: true

Size: 890 Bytes

Versions: 10

Compression:

Stored size: 890 Bytes

Contents

module ZTK

  # PTY Error Class
  #
  # @author Zachary Patten <zpatten AT jovelabs DOT io>
  class PTYError < Error; end

  # Ruby PTY Class Wrapper
  #
  # Wraps the Ruby PTY class, providing better functionality.
  #
  # @author Zachary Patten <zpatten AT jovelabs DOT io>
  class PTY
    require 'pty'

    class << self

      # Execute a process via a ruby-based PTY.
      #
      # @param [Array] args An argument splat to be passed to PTY::spawn
      #
      # @return [Object] Returns the $? object.
      def spawn(*args, &block)
        begin
          ::PTY.spawn(*args) do |reader, writer, pid|
            begin
              block_given? and yield(reader, writer, pid)
            rescue Errno::EIO
            ensure
              ::Process.wait(pid)
            end
          end
        rescue ::PTY::ChildExited
        end

        true
      end

    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ztk-3.3.2 lib/ztk/pty.rb
ztk-3.3.1 lib/ztk/pty.rb
ztk-3.3.0 lib/ztk/pty.rb
ztk-3.2.6 lib/ztk/pty.rb
ztk-3.2.5 lib/ztk/pty.rb
ztk-3.2.4 lib/ztk/pty.rb
ztk-3.2.3 lib/ztk/pty.rb
ztk-3.2.2 lib/ztk/pty.rb
ztk-3.2.1 lib/ztk/pty.rb
ztk-3.2.0 lib/ztk/pty.rb