From 9da58723f3277808006e8846da0ba1cf0791b421 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Mon, 6 Apr 2020 11:58:11 -0700 Subject: [PATCH] Added missing changes that were only in the server repo Added null check for stream.push --- modules/win-terminal.js | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/modules/win-terminal.js b/modules/win-terminal.js index 437df13..592e61b 100644 --- a/modules/win-terminal.js +++ b/modules/win-terminal.js @@ -146,9 +146,13 @@ function windows_terminal() { this.StartEx = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT, terminalTarget) { + // The older windows terminal does not support + CONSOLE_SCREEN_WIDTH = 80; + CONSOLE_SCREEN_HEIGHT = 25; + if (this._stream != null) { - throw ('Concurrent Terminal sessions are not supported on Windows'); + throw ('Concurrent terminal sessions are not supported on Windows.'); } this.stopping = null; if (this._kernel32.GetConsoleWindow().Val == 0) { @@ -399,9 +403,6 @@ function windows_terminal() { } this._WriteCharacter = function (key, bControlKey) { - var scanCode = this._user32.VkKeyScanA(key).Val & 0xFF; - if (key == 10) { return; } - var rec = GM.CreateVariable(20); rec.Deref(0, 2).toBuffer().writeUInt16LE(KEY_EVENT); // rec.EventType rec.Deref(4, 4).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.bKeyDown @@ -409,7 +410,7 @@ function windows_terminal() { rec.Deref(14, 1).toBuffer()[0] = key; // rec.Event.KeyEvent.uChar.AsciiChar rec.Deref(8, 2).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.wRepeatCount rec.Deref(10, 2).toBuffer().writeUInt16LE(this._user32.VkKeyScanA(key).Val); // rec.Event.KeyEvent.wVirtualKeyCode - rec.Deref(12, 2).toBuffer().writeUInt16LE(this._user32.MapVirtualKeyA(scanCode, MAPVK_VK_TO_VSC).Val); + rec.Deref(12, 2).toBuffer().writeUInt16LE(this._user32.MapVirtualKeyA(this._user32.VkKeyScanA(key).Val, MAPVK_VK_TO_VSC).Val); var dwWritten = GM.CreateVariable(4); if (this._kernel32.WriteConsoleInputA(this._stdinput, rec, 1, dwWritten).Val == 0) { return (false); } @@ -478,23 +479,28 @@ function windows_terminal() { return (retVal); } - this._SendDataBuffer = function (data) { + this._SendDataBuffer = function (data) + { // { data, attributes, width, height, x, y } - - var dy, line, attr; - for (dy = 0; dy < data.height; ++dy) { - line = data.data[dy]; - attr = data.attributes[dy]; - line.s = line.toString(); - - //line = data.data.slice(data.width * dy, (data.width * dy) + data.width); - //attr = data.attributes.slice(data.width * dy, (data.width * dy) + data.width); - this._stream.push(TranslateLine(data.x + 1, data.y + dy + 1, line, attr)); + if (this._stream != null) + { + var dy, line, attr; + for (dy = 0; dy < data.height; ++dy) + { + line = data.data[dy]; + attr = data.attributes[dy]; + line.s = line.toString(); + + //line = data.data.slice(data.width * dy, (data.width * dy) + data.width); + //attr = data.attributes.slice(data.width * dy, (data.width * dy) + data.width); + this._stream.push(TranslateLine(data.x + 1, data.y + dy + 1, line, attr)); + } } } - this._SendScroll = function _SendScroll(dx, dy) { - if (this._scrollTimer) { return; } + this._SendScroll = function _SendScroll(dx, dy) + { + if (this._scrollTimer || this._stream == null) { return; } var info = GM.CreateVariable(22); if (this._kernel32.GetConsoleScreenBufferInfo(this._stdoutput, info).Val == 0) { throw ('Error getting screen buffer info'); }