Sha256: 8eaf2cbf8f72a289c0172c4ea99aed10d439a96477d56a2dd5f5e502f9ed8228

Contents?: true

Size: 529 Bytes

Versions: 5

Compression:

Stored size: 529 Bytes

Contents

# frozen_string_literal: true

require 'pty'

module Junction
  class Session
    attr_reader :name, :pid, :output

    def initialize(name, command = 'bash')
      @name = name
      @command = command
      @output, @input, @pid = PTY.spawn(command)
    end

    def write(input)
      @input.puts(input)
    end

    def read
      @output.read_nonblock(1024)
    rescue IO::WaitReadable
      ''
    end

    def close
      Process.kill('KILL', @pid)
    rescue Errno::ESRCH
      # Process already exited
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
junction-0.1.5 lib/junction/session.rb
junction-0.1.4 lib/junction/session.rb
junction-0.1.3 lib/junction/session.rb
junction-0.1.2 lib/junction/session.rb
junction-0.1.1 lib/junction/session.rb