   injectJS: ->
     if @page.evaluate(-> window.mocha?)
       @page.injectJs 'mocha-phantomjs/core_extensions.js'
-      @customizeProcessStdout()
-      @customizeConsole()
+      @page.evaluate @customizeProcessStdout, @customizeOptions()
+      @page.evaluate @customizeConsole, @customizeOptions()
     else
       @fail "Failed to find mocha on the page."
 


  # Subclass Hooks

  customizeProcessStdout: -> 
    undefined

  customizeConsole: ->
    undefined

  # Private


  constructor: ->
    super 'spec'

  customizeProcessStdout: (options) ->
    process.stdout.write = (string) ->
      return if string is process.cursor.deleteLine or string is process.cursor.beginningOfLine
      console.log string

  customizeConsole: (options) ->
    process.cursor.CRMatcher = /\s+◦\s\w/
    process.cursor.CRCleaner = process.cursor.up + process.cursor.deleteLine
    origLog = console.log
    console.log = ->
      string = console.format.apply(console, arguments)
      if process.cursor.CRMatcher and string.match(process.cursor.CRMatcher)
        process.cursor.CRCleanup = true
      else if process.cursor.CRCleanup and process.cursor.CRCleaner
        string = process.cursor.CRCleaner + string
        process.cursor.CRCleanup = false
      origLog.call console, string

class Dot extends Reporter

  constructor: ->
    super 'dot'

  customizeProcessStdout: (options) ->
    process.stdout.write = (string) ->
      if string.match /\u001b\[\d\dm\․\u001b\[0m/
        ++process.cursor.count
        forward = process.cursor.count + 2
        string = process.cursor.up + process.cursor.forwardN(forward) + string
      console.log string

reporterString = system.args[2] || 'spec'
reporterString = reporterString.charAt(0).toUpperCase() + reporterString.slice(1)
