Sha256: 4342d284b491c45987190c65bc01964a7c75af3dac4b31952b84a371e81bb77a

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby
require 'pty'
require 'open3'
require 'readline'
STDOUT.sync = true
bin = "#{Gem.bin_path('voltos', 'voltos')}-cli"
if STDIN.tty?
  status = PTY.spawn(bin, *ARGV) do |stdout, stdin, pid|
    stdout.sync = true
    Thread.new do
      loop do
        STDOUT.print stdout.getc
      end
    end
    Thread.new do
      loop do
        input = Readline.readline("", true)
        if input.nil?
          stdout.flush
          stdout.close
          stdin.close
        end
        stdin.puts input.strip
      end
    end
    begin
      Process::waitpid(pid) rescue nil
      while out = stdout.getc do
        STDOUT.print out
      end
    rescue SystemExit, Interrupt
      Process.kill('INT', pid)
      retry
    rescue EOFError
      puts "Ctrl-D"
    rescue IOError
    end
  end
else
  Open3.popen3(bin, *ARGV) do |stdin, stdout, stderr, thread|
    errThread = Thread.new do
      while !stderr.eof?  do
        putc stderr.readchar
      end
    end
    outThread = Thread.new do
      while !stdout.eof?  do
        putc stdout.readchar
      end
    end
    Process::waitpid(thread.pid) rescue nil
    errThread.join
    outThread.join
    process = thread.value
    status = process.exitstatus.to_i if !process.nil?
  end
end
exit(status.to_i)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voltos-0.3.0.rc11 exe/voltos