<commit_before>Readline = require 'readline'

Robot    = require '../robot'
Adapter  = require '../adapter'

class Shell extends Adapter
  send: (user, strings...) ->
    unless process.platform is "win32"
      console.log "\033[01;32m#{str}\033[0m" for str in strings
    else
      console.log "#{str}" for str in strings
    @repl.prompt()

  reply: (user, strings...) ->
    @send user, strings...

  run: ->
    stdin = process.openStdin()
    stdout = process.stdout

    process.on "uncaughtException", (err) =>
      @robot.logger.error "#{err}"

    @repl = Readline.createInterface stdin, stdout, null

    @repl.on "close", =>
      stdin.destroy()
      @robot.shutdown()
      process.exit 0

    @repl.on "line", (buffer) =>
      @repl.close() if buffer.toLowerCase() is "exit"
      @repl.prompt()
      user = @userForId '1', name: "Shell"
      @receive new Robot.TextMessage user, buffer

    @repl.setPrompt "#{@robot.name}> "
    @repl.prompt()

exports.use = (robot) ->
  new Shell robot
<commit_msg>Specify a room for the shell adapter<commit_after>Readline = require 'readline'

Robot    = require '../robot'
Adapter  = require '../adapter'

class Shell extends Adapter
  send: (user, strings...) ->
    unless process.platform is "win32"
      console.log "\033[01;32m#{str}\033[0m" for str in strings
    else
      console.log "#{str}" for str in strings
    @repl.prompt()

  reply: (user, strings...) ->
    @send user, strings...

  run: ->
    stdin = process.openStdin()
    stdout = process.stdout

    process.on "uncaughtException", (err) =>
      @robot.logger.error "#{err}"

    @repl = Readline.createInterface stdin, stdout, null

    @repl.on "close", =>
      stdin.destroy()
      @robot.shutdown()
      process.exit 0

    @repl.on "line", (buffer) =>
      @repl.close() if buffer.toLowerCase() is "exit"
      @repl.prompt()
      user = @userForId '1', name: "Shell", room: "Shell"
      @receive new Robot.TextMessage user, buffer

    @repl.setPrompt "#{@robot.name}> "
    @repl.prompt()

exports.use = (robot) ->
  new Shell robot

{'fraction_non_alphanumeric': 0.15834932821497122, 'fraction_numerical': 0.014395393474088292, 'mean_word_length': 2.690265486725664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089308', 'n_tokens_mistral': 735, 'n_tokens_neox': 700, 'n_words': 184}