#!/usr/bin/env ruby
require 'pty'
require 'readline'
bin = "#{Gem.bin_path('voltos', 'voltos')}-cli"
status = PTY.spawn(bin, *ARGV) do |stdout, stdin, pid|
  Thread.new do
    loop { STDOUT.print stdout.getc }
  end
  Thread.new do
    input = Readline.readline("", true).strip
    stdin.puts input
  end
  begin
    Process::waitpid(pid) rescue nil
  rescue SystemExit, Interrupt
    Process.kill('INT', pid)
    retry
  end
end
exit(status.to_i)