"use strict";
var spawn = require("child_process").spawn,
    colors = require("chalk");

var Child = function(cmd, args) {
  this.cmd = cmd;
  this.args = args;

  process.on("exit", function() {
    if (!this.running) return;
    this.proc.kill("SIGTERM");
  }.bind(this));
};

Child.prototype.start = function() {
  if (this.running) return;
  var sig = "["+colors.green("bg")+"]";
  console.log(sig, "Starting", this.cmd, this.args.join(" "));

  this.proc = spawn(this.cmd, this.args);

  this.proc.stdout.on("data", this.log);
  this.proc.stderr.on("data", this.err);
  this.proc.on("exit", this.exit.bind(this));

  this.running = true;
};

Child.prototype.restart = function() {
  if (!this.running) return this.start();

  this.proc.removeAllListeners("exit").on("exit", function() {
    this.running = false;
    this.start();
  }.bind(this));

  this.proc.kill("SIGTERM");
};

Child.prototype.exit = function(code) {
  var fn = code === 0 ? "log" : "err";
  this[fn]("Exited with code "+code);
  this.running = false;
};

Child.prototype.log = function(buff) { 
  var msg = buff.toString().trim();
  var sig = "["+colors.gray("bg")+"]";
  console.log(sig, msg);
};

Child.prototype.err = function(buff) {
  var msg = buff.toString().trim();
  var sig = "["+colors.red("bg")+"]";

  if (!msg) return;
  console.log(sig, msg);
};

var plugin = module.exports = function(cmd, args) {
  if (!(args instanceof Array)) {
    args = Array.prototype.slice.call(arguments, 1);
  }
  
  var child = new Child(cmd, args);

  return child.restart.bind(child);
};

@@ -485,94 +485,34 @@
 args
-);%0A%0A  this.proc.stdout.on(%22data%22, this.log);%0A  this.proc.stderr.on(%22data%22, this.err
+, %7B stdio: 'inherit' %7D
 );%0A
+%0A
   th
@@ -867,356 +867,119 @@
 %7B%0A  
-var fn = code === 0 ? %22log%22 : %22err%22;%0A  this%5Bfn%5D(%22Exited with code %22+code);%0A  this.running = false;%0A%7D;%0A%0AChild.prototype.log = function(buff) %7B %0A  var msg = buff.toString().trim();%0A  var sig = %22%5B%22+colors.gray(%22bg%22)+%22%5D%22;%0A  console.log(sig, msg);%0A%7D;%0A%0AChild.prototype.err = function(buff) %7B%0A  var msg = buff.toString().trim();%0A  var sig = %22%5B%22+colors.
+this.running = false;%0A  var msg = %22Exited with code %22+code;%0A  var sig = %22%5B%22+colors%5Bcode === 0 ? %22gray%22 : %22
 red
+%22%5D
 (%22bg
@@ -989,29 +989,8 @@
 %22%5D%22;
-%0A%0A  if (!msg) return;
 %0A  c
@@ -1158,18 +1158,16 @@
 1);%0A  %7D%0A
-  
 %0A  var c

use parent's stdios