 Cline = require('cline')
+fs    = require('fs')
+readline = require('readline')
+stream = require('stream')
+util = require('util')
+
 Robot         = require '../robot'
 Adapter       = require '../adapter'
 {TextMessage} = require '../message'

    strings = strings.map (s) -> "#{envelope.user.name}: #{s}"
    @send envelope, strings...

  run: ->
    @cli = Cline()

    @cli.command "*", (input) =>

    @cli.command 'history', () =>
      console.log @cli.history()

    #@cli.on 'command', (input, cmd) ->
    #  console.log "on command #{input}"
    @cli.on 'history', (item) =>
      if item.length > 0 and item isnt 'exit'
        console.log "adding #{item} to the history"

        fs.appendFile '.hubot_history', "#{item}\n", (err) =>
          @robot.emit 'error', err


    @cli.on 'close', () =>
      console.log "on close!"
      @robot.shutdown()
      process.exit 0

  run: ->
    @buildCli()

    @loadHistory (history) =>
      @cli.history(history)
      @cli.interact("#{@robot.name}> ")
      @emit 'connected'


exports.use = (robot) ->
