         @emitter.emit('data', data)
         @term.write data
 
-      @ptyProcess.on 'exit', ->
+      @ptyProcess.on 'exit', (data) =>
         @emitter.emit('exit', data)
-        @destroy()
+        @exit()
+    else
+      term.end = => @exit()
 
     @input "#{runCommand}#{os.EOL}" if (runCommand)
-
     term.focus()
-
     @applyStyle()
     @attachEvents()
-
-    window.TermView = this
+    @resizeToPane
 
   resize: (cols, rows) ->
     return if @term.rows is rows and @term.cols is cols

      colors, cursorBlink, scrollback, cols, rows
    }

    term.end = => @destroy()

    term.on "data", (data) => @input data
    term.open this.get(0)


    @fakeRow.remove()
    {cols, rows}

  exit: ->
    pane = atom.workspace.getActivePane()
    pane.destroyItem(this);

  destroy: ->
    @off 'focus', @focus
    $(window).off 'resize', @resizeToPane
    if @ptyProcess
      @ptyProcess.kill()
      @ptyProcess = null
    if @term
      @term.destroy()
      @term = null
    if @disposable
      @disposable.dispose()
      @disposable = null


module.exports = TermView
