var rl = require('readline'); function quit() { i.close(); process.stdin.destroy(); process.exit(0); } var i; module.exports.init = function() { process.stdin.resume(); i = rl.createInterface(process.stdin, process.stdout, null); } module.exports.setupRepl = function() { } module.exports.setupSimulatorRepl = function(config) { var from = 'alice!~alice@example.com'; var channel = config.channel; function updatePrompt() { var prefix = 'from=' + from; prefix += channel ? ', channel=' + channel : ''; prefix += '> '; i.setPrompt(prefix, prefix.length); i.prompt(); } i.on('line', function (cmd) { cmd = cmd.trim(); if(cmd.length == 0) { i.prompt(); return; } var parts = cmd.split(' '); switch(parts[0]) { case '/quit': case '/q': quit(); break; case '/raw': case '/r': parts.shift(); stdinPipe.send(parts.join(' ')); updatePrompt(); break; case '/join': case '/j': channel = parts[1]; updatePrompt(); break; case '/from': case '/f': from = parts[1]; updatePrompt(); break; case '/notice': case '/n': if(channel) { parts.shift(); stdinPipe.send(':' + from + ' NOTICE ' + channel + ' :' + parts.join(' ')); } else { info('You have to /j a channel first'); } break; default: stdinPipe.send(':' + from + ' PRIVMSG ' + channel + ' :' + parts.join(' ')); updatePrompt(); break; } }).on('close', function() { quit(); }); updatePrompt(); setTimeout(function() { stdinPipe.send(':irc.foo.bar 001 this :Welcome to Some Internet Relay Chat Network this'); }, 1000); }