     '\\': '\\\\'
     '\u001b': '\\e'
 
-  constructor: (@container) ->
+  constructor: (containerView) ->
     localStorage?["WebTerm.logRawOutput"] ?= "false"
     localStorage?["WebTerm.slowDrawing"]  ?= "false"
 
-    @server = null
+    @parent               = containerView
+    @container            = containerView.$()
+    @server               = null
     @sessionEndedCallback = null
-    @setTitleCallback = null
+    @setTitleCallback     = null
 
     @keyInput = new KDCustomHTMLView
       tagName: 'input'

    @server.setSize x, y if @server

  updateSize: (force=no) ->
    return if not force and @pixelWidth is @container.prop("clientWidth") and @pixelHeight is @container.prop("clientHeight")
    @container.scrollTop @container.scrollTop() + @pixelHeight - @container.prop("clientHeight") + 1 if @container.prop("clientHeight") < @pixelHeight
    @pixelWidth  = @container.prop("clientWidth")
    @pixelHeight = @container.prop("clientHeight")

    width = 1
    height = 1
    for n in [0..10] # avoid infinite loop
      text = ""
      text += "\xA0" for x in [0...width]
      elements = []
      for y in [0...height]
        div = $(document.createElement("div"))
        div.text text
        elements.push div
      @measurebox.empty()
      @measurebox.append elements
      break if newWidth is width and newHeight is height
      break if newWidth > 1000 or newHeight > 1000 # sanity check
      newWidth  = Math.max width,  Math.floor @pixelWidth  / @measurebox.width()  * width
      newHeight = Math.max height, Math.floor @pixelHeight / @measurebox.height() * height
      width = newWidth
      height = newHeight

    @measurebox.empty()

    @cursor            = new WebTerm.Cursor(this)
    @controlCodeReader = WebTerm.createAnsiControlCodeReader(this)

    @measurebox = $("div")
    @measurebox.css
      position   : "absolute"
      visibility : "hidden"
    @container.append @measurebox
    @updateSize()

