Add callbacks to write methods
This commit is contained in:
parent
7b521d8699
commit
f292944992
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue