       rendered += text.length
 
     if cursorX
-      x = cursorX * @cellWidth
-      @ctx.fillStyle = AsciiIo.colors[7]
-      @ctx.fillRect x, top, @cellWidth, @cellHeight
-      if cursorText
-        @ctx.fillStyle = AsciiIo.colors[0]
-        @ctx.fillText cursorText, x, top + @cellHeight
+      @renderCursor()
 
   setBackgroundAttributes: (brush) ->
     @ctx.fillStyle = AsciiIo.colors[brush.bgColor()]

      [text, brush] = fragment

      if cursorX isnt undefined and rendered <= cursorX < rendered + text.length
        cursorText = text[cursorX - rendered]

      @setBackgroundAttributes(brush)
      @ctx.fillRect left, top, text.length * @cellWidth, @cellHeight

      @ctx.font = font
      @prevFont = font

  renderCursor: ->
    return unless @cursorOn and @cursorText

    x = @cursorX * @cellWidth
    y = @cursorY * @cellHeight

    if @cursorVisible
      @ctx.fillStyle = AsciiIo.colors[7]
      @ctx.fillRect x, y, @cellWidth, @cellHeight
      @ctx.fillStyle = AsciiIo.colors[0]
      @ctx.fillText @cursorText, x, y + @cellHeight
    else
      @ctx.fillStyle = AsciiIo.colors[@cursorBrush.bgColor()]
      @ctx.fillRect x, y, @cellWidth, @cellHeight
      @ctx.fillStyle = AsciiIo.colors[@cursorBrush.fgColor()]
      @ctx.fillText @cursorText, x, y + @cellHeight

    console.log @cursorY
    console.log @cursorVisible
    console.log @cursorOn

  showCursor: (show) ->
    @cursorOn = show

  blinkCursor: ->
    @cursorVisible = !@cursorVisible
    @renderCursor()

  resetCursorState: ->
    @cursorVisible = true
    @renderCursor()
