1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-28 06:03:25 +00:00

Modifed win-terminal, so it throws an exception if concurrent sessions are attempted. (Not supported, so throwing an exception allows us to propagate an error)

This commit is contained in:
Bryan Roe
2019-08-13 22:34:48 -07:00
parent e87d1d5db1
commit 6f8e813024

View File

@@ -146,6 +146,10 @@ function windows_terminal() {
this.StartEx = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT, terminalTarget)
{
if (this._stream != null)
{
throw ('Concurrent Terminal sessions are not supported on Windows');
}
this.stopping = null;
if (this._kernel32.GetConsoleWindow().Val == 0) {
if (this._kernel32.AllocConsole().Val == 0) {
@@ -180,45 +184,59 @@ function windows_terminal() {
// Hook Ready
this.terminal.StartCommand(this.userArgs[0]);
}, console.log);
this._stream = new duplex({
'write': function (chunk, flush) {
if (!this.terminal.connected) {
//console.log('_write: ' + chunk);
if (!this._promise.chunk) {
this._promise.chunk = [];
}
if (typeof (chunk) == 'string') {
this._promise.chunk.push(chunk);
} else {
this._promise.chunk.push(Buffer.alloc(chunk.length));
chunk.copy(this._promise.chunk.peek());
}
this._promise.chunk.peek().flush = flush;
this._promise.then(function () {
var buf;
while (this.chunk.length > 0) {
buf = this.chunk.shift();
this.terminal._WriteBuffer(buf);
buf.flush();
this._stream = new duplex(
{
'write': function (chunk, flush)
{
if (!this.terminal.connected)
{
//console.log('_write: ' + chunk);
if (!this._promise.chunk)
{
this._promise.chunk = [];
}
});
if (typeof (chunk) == 'string')
{
this._promise.chunk.push(chunk);
} else
{
this._promise.chunk.push(Buffer.alloc(chunk.length));
chunk.copy(this._promise.chunk.peek());
}
this._promise.chunk.peek().flush = flush;
this._promise.then(function ()
{
var buf;
while (this.chunk.length > 0)
{
buf = this.chunk.shift();
this.terminal._WriteBuffer(buf);
buf.flush();
}
});
}
else
{
//console.log('writeNOW: ' + chunk);
this.terminal._WriteBuffer(chunk);
flush();
}
return (true);
},
'final': function (flush)
{
var p = this.terminal._stop();
p.__flush = flush;
p.then(function () { this.__flush(); });
}
else {
//console.log('writeNOW: ' + chunk);
this.terminal._WriteBuffer(chunk);
flush();
}
return (true);
},
'final': function (flush) {
var p = this.terminal._stop();
p.__flush = flush;
p.then(function () { this.__flush(); });
}
});
});
this._stream.terminal = this;
this._stream._promise = new promise(function (res, rej) { this._res = res; this._rej = rej; });
this._stream._promise.terminal = this;
this._stream.prependOnceListener('end', function ()
{
this.terminal._stream = null;
});
return (this._stream);
};
this.Start = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT)