 
   constructor: (@reporter) ->
     @url = system.args[1]
+    @columns = parseInt(system.env.COLUMNS or 75) * .75 | 0
     @mochaStarted = false
     @mochaStartWait = 6000
     @fail(USAGE) unless @url

  constructor: ->
    super 'spec'

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

  customizeConsole: ->
    @page.evaluate ->
      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: ->
    @page.evaluate ->
      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)

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

