Add callbacks to write methods

This commit is contained in:
Bryan Ashby 2016-01-02 12:11:40 -07:00
parent 7b521d8699
commit f292944992
1 changed files with 10 additions and 7 deletions

View File

@ -144,21 +144,23 @@ ClientTerminal.prototype.isANSI = function() {
// :TODO: probably need to update these to convert IAC (0xff) -> IACIAC (escape it) // :TODO: probably need to update these to convert IAC (0xff) -> IACIAC (escape it)
ClientTerminal.prototype.write = function(s, convertLineFeeds) { ClientTerminal.prototype.write = function(s, convertLineFeeds, cb) {
this.rawWrite(this.encode(s, convertLineFeeds)); this.rawWrite(this.encode(s, convertLineFeeds), cb);
}; };
ClientTerminal.prototype.rawWrite = function(s) { ClientTerminal.prototype.rawWrite = function(s, cb) {
if(this.output) { if(this.output) {
this.output.write(s, function written(err) { this.output.write(s, function written(err) {
if(err) { if(_.isFunction(cb)) {
cb(err);
} else if(err) {
Log.warn('Failed writing to socket: ' + err.toString()); Log.warn('Failed writing to socket: ' + err.toString());
} }
}); });
} }
}; };
ClientTerminal.prototype.pipeWrite = function(s, spec) { ClientTerminal.prototype.pipeWrite = function(s, spec, cb) {
spec = spec || 'renegade'; spec = spec || 'renegade';
var conv = { var conv = {
@ -166,11 +168,12 @@ ClientTerminal.prototype.pipeWrite = function(s, spec) {
renegade : renegadeToAnsi, renegade : renegadeToAnsi,
}[spec] || enigmaToAnsi; }[spec] || enigmaToAnsi;
this.write(conv(s, this)); this.write(conv(s, this), null, cb); // null = use default for |convertLineFeeds|
}; };
ClientTerminal.prototype.encode = function(s, convertLineFeeds) { ClientTerminal.prototype.encode = function(s, convertLineFeeds) {
convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds; convertLineFeeds = _.isBoolean(convertLineFeeds) ? convertLineFeeds : this.convertLF;
if(convertLineFeeds && _.isString(s)) { if(convertLineFeeds && _.isString(s)) {
s = s.replace(/\n/g, '\r\n'); s = s.replace(/\n/g, '\r\n');
} }