iocat
Version:
WebSocket netcat with Socket.io support
76 lines (61 loc) • 2.14 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var Base, Shell, readline,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Base = require('./Base').Base;
readline = require('readline');
Shell = (function(superClass) {
extend(Shell, superClass);
function Shell(options) {
var base, base1;
this.options = options != null ? options : {};
this.close = bind(this.close, this);
this.send = bind(this.send, this);
this.exit = bind(this.exit, this);
this.onSigint = bind(this.onSigint, this);
this.onLine = bind(this.onLine, this);
this.start = bind(this.start, this);
if ((base = this.options).input == null) {
base.input = process.stdin;
}
if ((base1 = this.options).output == null) {
base1.output = process.stdout;
}
this.stdin = process.stdin;
this.stdout = process.stdout;
return this;
}
Shell.prototype.start = function() {
this.rl = readline.createInterface(this.options);
this.rl.on('line', this.onLine);
this.rl.on('SIGINT', this.onSigint);
return this.rl.prompt();
};
Shell.prototype.onLine = function(d) {
this.log('onLine', d);
this.emit('line', d);
return this.rl.prompt();
};
Shell.prototype.onSigint = function() {
this.log('onSigint');
return this.emit('SIGINT');
};
Shell.prototype.exit = function(code) {
this.log('exit:', code);
return process.exit(code);
};
Shell.prototype.send = function(d) {
this.log('write', d);
return console.log(d);
};
Shell.prototype.close = function() {
return this.log('close');
};
return Shell;
})(Base);
module.exports = {
Shell: Shell
};
}).call(this);