Implement buffered attaching

Fixes #21
This commit is contained in:
Paris 2015-02-24 20:55:52 +02:00
parent 6cfd957697
commit 932ab00a53

View File

@ -19,14 +19,34 @@
attach(this.Xterm); attach(this.Xterm);
} }
})(function (Xterm) { })(function (Xterm) {
Xterm.prototype.attach = function (socket, bidirectional) { Xterm.prototype.attach = function (socket, bidirectional, buffered) {
var term = this; var term = this;
bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional; bidirectional = (typeof bidirectional == 'undefined') ? true : bidirectional;
this.socket = socket; this.socket = socket;
term._flushBuffer = function () {
term.write(term._attachSocketBuffer);
term._attachSocketBuffer = null;
clearTimeout(term._attachSocketBufferTimer);
term._attachSocketBufferTimer = null;
};
term._pushToBuffer = function (data) {
if (term._attachSocketBuffer) {
term._attachSocketBuffer += data;
} else {
term._attachSocketBuffer = data;
setTimeout(term._flushBuffer, 10);
}
};
term._getMessage = function (ev) { term._getMessage = function (ev) {
term.write(ev.data); if (buffered) {
term._pushToBuffer(ev.data);
} else {
term.write(ev.data);
}
}; };
term._sendData = function (data) { term._sendData = function (data) {