Browse files

A repl

  • Loading branch information...
1 parent b69769d commit 77beeeecd2253bb0bb407989fd59c4818023212d @isaacs committed May 18, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 eliza-repl.js
View
42 eliza-repl.js
@@ -0,0 +1,42 @@
+var readline = require('readline')
+
+var rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout
+})
+
+rl._prompt = '> '
+
+var ElizaBot = require('./elizabot.js')
+var eliza = new ElizaBot
+eliza.memSize = 1024
+
+function say (line) {
+ console.log('ELIZA: ' + line)
+ process.stdout.write(rl._prompt)
+}
+
+rl.on('line', function (line) {
+ line = line.trim()
+ if (!line) return
+
+ // user asked a question
+ if (line === '.reset') {
+ console.log(eliza.getFinal())
+ eliza.reset()
+ say(eliza.getInitial())
+ process.stdout.write(rl._prompt)
+ return
+ }
+ if (line === '.quit') {
+ process.exit()
+ return
+ }
+ var reply = eliza.transform(line)
+ say(reply)
+ if (eliza.quit) {
+ process.exit()
+ }
+})
+
+say(eliza.getInitial())

0 comments on commit 77beeee

Please sign in to comment.