Added terminal sizing support.

This commit is contained in:
Ylian Saint-Hilaire 2019-06-05 13:28:43 -07:00
parent 15aaecf171
commit 184a95b3ce
4 changed files with 81 additions and 38 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.3.5-y", "version": "0.3.5-z",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -5,9 +5,10 @@
*/ */
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
// https://www.x.org/docs/xterm/ctlseqs.pdf
// Construct a MeshServer object // Construct a MeshServer object
var CreateAmtRemoteTerminal = function (divid) { var CreateAmtRemoteTerminal = function (divid, options) {
var obj = {}; var obj = {};
obj.DivId = divid; obj.DivId = divid;
obj.DivElement = document.getElementById(divid); obj.DivElement = document.getElementById(divid);
@ -44,7 +45,7 @@ var CreateAmtRemoteTerminal = function (divid) {
var _VTREVERSE = 2; var _VTREVERSE = 2;
var _backSpaceErase = false; var _backSpaceErase = false;
var _cursorVisible = true; var _cursorVisible = true;
var _scrollRegion = [0, 24]; var _scrollRegion;
var _altKeypadMode = false; var _altKeypadMode = false;
var scrollBackBuffer = []; var scrollBackBuffer = [];
obj.title = null; obj.title = null;
@ -64,7 +65,9 @@ var CreateAmtRemoteTerminal = function (divid) {
obj.TermDraw(); obj.TermDraw();
} }
obj.xxStateChange = function(newstate) { } obj.xxStateChange = function (newstate) {
if ((newstate == 3) && (options != null) && (options.xterm == true)) { obj.TermSendKeys('stty rows ' + obj.height + ' cols ' + obj.width + '\nclear\n'); }
}
obj.ProcessData = function (str) { obj.ProcessData = function (str) {
if (obj.debugmode == 2) { console.log("TRecv(" + str.length + "): " + rstr2hex(str)); } if (obj.debugmode == 2) { console.log("TRecv(" + str.length + "): " + rstr2hex(str)); }
@ -250,14 +253,14 @@ var CreateAmtRemoteTerminal = function (divid) {
if (argslen == 1) { if (argslen == 1) {
_termx = args[0] - 1; _termx = args[0] - 1;
if (_termx < 0) _termx = 0; if (_termx < 0) _termx = 0;
if (_termx > 79) _termx = 79; if (_termx > (obj.width - 1)) _termx = (obj.width - 1);
} }
break; break;
case 'P': // Delete X Character(s), default 1 char case 'P': // Delete X Character(s), default 1 char
var x = 1; var x = 1;
if (argslen == 1) { x = args[0]; } if (argslen == 1) { x = args[0]; }
for (i = _termx; i < 80 - x; i++) { _tscreen[_termy][i] = _tscreen[_termy][i + x]; _scratt[_termy][i] = _scratt[_termy][i + x]; } for (i = _termx; i < obj.width - x; i++) { _tscreen[_termy][i] = _tscreen[_termy][i + x]; _scratt[_termy][i] = _scratt[_termy][i + x]; }
for (i = (80 - x); i < 80; i++) { _tscreen[_termy][i] = ' '; _scratt[_termy][i] = (7 << 6); } for (i = (obj.width - x); i < obj.width; i++) { _tscreen[_termy][i] = ' '; _scratt[_termy][i] = (7 << 6); }
break; break;
case 'L': // Insert X Line(s), default 1 char case 'L': // Insert X Line(s), default 1 char
var linecount = 1; var linecount = 1;
@ -369,9 +372,9 @@ var CreateAmtRemoteTerminal = function (divid) {
case 'r': // Set the scroll region case 'r': // Set the scroll region
if (argslen == 2) { _scrollRegion = [args[0] - 1, args[1] - 1]; } if (argslen == 2) { _scrollRegion = [args[0] - 1, args[1] - 1]; }
if (_scrollRegion[0] < 0) { _scrollRegion[0] = 0; } if (_scrollRegion[0] < 0) { _scrollRegion[0] = 0; }
if (_scrollRegion[0] > 24) { _scrollRegion[0] = 24; } if (_scrollRegion[0] > (obj.height - 1)) { _scrollRegion[0] = (obj.height - 1); }
if (_scrollRegion[1] < 0) { _scrollRegion[1] = 0; } if (_scrollRegion[1] < 0) { _scrollRegion[1] = 0; }
if (_scrollRegion[1] > 24) { _scrollRegion[1] = 24; } if (_scrollRegion[1] > (obj.height - 1)) { _scrollRegion[1] = (obj.height - 1); }
if (_scrollRegion[0] > _scrollRegion[1]) { _scrollRegion[0] = _scrollRegion[1]; } if (_scrollRegion[0] > _scrollRegion[1]) { _scrollRegion[0] = _scrollRegion[1]; }
break; break;
case 'S': // Scroll up the scroll region X lines, default 1 case 'S': // Scroll up the scroll region X lines, default 1
@ -597,7 +600,7 @@ var CreateAmtRemoteTerminal = function (divid) {
_TermLineWrap = _cursorVisible = true; _TermLineWrap = _cursorVisible = true;
_termx = _termy = 0; _termx = _termy = 0;
_backSpaceErase = false; _backSpaceErase = false;
_scrollRegion = [0, 24]; _scrollRegion = [0, (obj.height - 1)];
_altKeypadMode = false; _altKeypadMode = false;
obj.TermClear(7 << 6); obj.TermClear(7 << 6);
} }
@ -626,8 +629,8 @@ var CreateAmtRemoteTerminal = function (divid) {
} }
} }
obj.TermSendKeys = function (keys) { if (obj.debugmode == 2) { console.log("TSend(" + keys.length + "): " + rstr2hex(keys)); } obj.parent.send(keys); } obj.TermSendKeys = function (keys) { if (obj.debugmode == 2) { console.log("TSend(" + keys.length + "): " + rstr2hex(keys), keys); } obj.parent.send(keys); }
obj.TermSendKey = function (key) { if (obj.debugmode == 2) { console.log("TSend(1): " + rstr2hex(String.fromCharCode(key))); } obj.parent.send(String.fromCharCode(key)); } obj.TermSendKey = function (key) { if (obj.debugmode == 2) { console.log("TSend(1): " + rstr2hex(String.fromCharCode(key)), key); } obj.parent.send(String.fromCharCode(key)); }
function _TermMoveUp(linecount) { function _TermMoveUp(linecount) {
var x, y; var x, y;
@ -730,7 +733,6 @@ var CreateAmtRemoteTerminal = function (divid) {
buf = r[0]; buf = r[0];
closetag = r[1]; closetag = r[1];
scrollBackBuffer.push(buf + closetag + '<br>'); scrollBackBuffer.push(buf + closetag + '<br>');
if (scrollBackBuffer.length > 800) { scrollBackBuffer = scrollBackBuffer.slice(0, 800); }
} }
obj.TermDrawLine = function (buf, y, closetag) { obj.TermDrawLine = function (buf, y, closetag) {
@ -771,8 +773,8 @@ var CreateAmtRemoteTerminal = function (divid) {
if (y != (obj.height - 1)) buf += '<br>'; if (y != (obj.height - 1)) buf += '<br>';
} }
var backbuffer = ''; if (scrollBackBuffer.length > 800) { scrollBackBuffer = scrollBackBuffer.slice(scrollBackBuffer.length - 800); }
for (var i in scrollBackBuffer) { backbuffer += scrollBackBuffer[i]; } var backbuffer = scrollBackBuffer.join('');
obj.DivElement.innerHTML = "<font size='4'><b>" + backbuffer + buf + closetag + "</b></font>"; obj.DivElement.innerHTML = "<font size='4'><b>" + backbuffer + buf + closetag + "</b></font>";
obj.DivElement.scrollTop = obj.DivElement.scrollHeight; obj.DivElement.scrollTop = obj.DivElement.scrollHeight;
if (obj.heightLock == 0) { setTimeout(obj.TermLockHeight, 10); } if (obj.heightLock == 0) { setTimeout(obj.TermLockHeight, 10); }
@ -786,6 +788,8 @@ var CreateAmtRemoteTerminal = function (divid) {
obj.TermInit = function () { obj.TermResetScreen(); } obj.TermInit = function () { obj.TermResetScreen(); }
obj.Init(); obj.heightLock = 0;
obj.DivElement.style['height'] = '';
if ((options != null) && (options.width != null) && (options.height != null)) { obj.Init(options.width, options.height); } else { obj.Init(); }
return obj; return obj;
} }

File diff suppressed because one or more lines are too long

View File

@ -547,6 +547,9 @@
<input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()"> <input id="id_tfxkeysbutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Intel (F10 = ESC+[OM)" title="Toggle F1 to F10 keys emulation type" onclick="termToggleFx()">
<input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()"> <input id="id_ttypebutton" type="button" onkeypress="return false" onkeydown="return false" class="bottombutton" value="Extended Ascii" title="Toggle terminal emulation type" onclick="termToggleType()">
</span> </span>
<span id="terminalSizeDropDown">
<select id="termSizeList" onkeypress="return false"><option value="1">80x25</option><option value="2">100x30</option><option value="3" selected>Auto</option></select>
</span>
<select id="specialkeylist" onkeypress="return false"></select> <select id="specialkeylist" onkeypress="return false"></select>
<input id="specialkeylistinput" type="button" onkeypress="return false" class="bottombutton" value="Send" title="Send the selected special key" onclick="sendSpecialKey()" /> <input id="specialkeylistinput" type="button" onkeypress="return false" class="bottombutton" value="Send" title="Send the selected special key" onclick="sendSpecialKey()" />
</div> </div>
@ -5035,14 +5038,17 @@
switch (state) { switch (state) {
case 0: case 0:
// Disconnected, clear the terminal // Disconnected, clear the terminal
QE('termSizeList', true);
QH('termtitle', ''); QH('termtitle', '');
xterminal.m.TermResetScreen(); xterminal.m.TermResetScreen();
xterminal.m.TermDraw(); xterminal.m.TermDraw();
if (terminal != null) { terminal.Stop(); terminal = null; } if (terminal != null) { terminal.Stop(); terminal = null; }
break; break;
case 3: case 3:
QE('termSizeList', false);
break; break;
default: default:
QE('termSizeList', false);
//console.log('Unhandled onTerminalStateChange state', state); //console.log('Unhandled onTerminalStateChange state', state);
break; break;
} }
@ -5058,7 +5064,9 @@
if (contype == 2) { if (contype == 2) {
// Setup the Intel AMT terminal // Setup the Intel AMT terminal
if ((terminalNode.intelamt.user == null) || (terminalNode.intelamt.user == '')) { editDeviceAmtSettings(terminalNode._id, connectTerminal); return; } if ((terminalNode.intelamt.user == null) || (terminalNode.intelamt.user == '')) { editDeviceAmtSettings(terminalNode._id, connectTerminal); return; }
terminal = CreateAmtRedirect(CreateAmtRemoteTerminal('Term'), authCookie); var termoptions = {};
if (Q('termSizeList').value == 2) { termoptions.width = 100; termoptions.height = 30; }
terminal = CreateAmtRedirect(CreateAmtRemoteTerminal('Term', termoptions), authCookie);
terminal.debugmode = debugmode; terminal.debugmode = debugmode;
terminal.m.debugmode = debugmode; terminal.m.debugmode = debugmode;
terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); } terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); }
@ -5068,7 +5076,17 @@
Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation]; Q('id_ttypebutton').value = terminalEmulations[terminal.m.terminalEmulation];
} else { } else {
// Setup a mesh agent terminal // Setup a mesh agent terminal
terminal = CreateAgentRedirect(meshserver, CreateAmtRemoteTerminal('Term'), serverPublicNamePort, authCookie, domainUrl); var termoptions = {};
if ([1, 2, 3, 4, 21, 22].indexOf(currentNode.agent.id) == -1) {
if (Q('termSizeList').value == 2) { termoptions.width = 100; termoptions.height = 30; termoptions.xterm = true; }
if (Q('termSizeList').value == 3) {
// TODO: Try to improve terminal auto-size.
termoptions.width = Math.floor((Q('column_l').clientWidth - 60) / 10);
termoptions.height = Math.floor((Q('column_l').clientHeight - 120) / 20);
termoptions.xterm = true;
}
}
terminal = CreateAgentRedirect(meshserver, CreateAmtRemoteTerminal('Term', termoptions), serverPublicNamePort, authCookie, domainUrl);
terminal.debugmode = debugmode; terminal.debugmode = debugmode;
terminal.m.debugmode = debugmode; terminal.m.debugmode = debugmode;
terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); } terminal.m.onTitleChange = function (sender, title) { QH('termtitle', ' - ' + EscapeHtml(title)); }
@ -5076,6 +5094,7 @@
terminal.attemptWebRTC = attemptWebRTC; terminal.attemptWebRTC = attemptWebRTC;
terminal.onStateChanged = onTerminalStateChange; terminal.onStateChanged = onTerminalStateChange;
terminal.onConsoleMessageChange = function () { terminal.onConsoleMessageChange = function () {
console.log('terminal.consoleMessage', terminal.consoleMessage);
p12clearConsoleMsg(); p12clearConsoleMsg();
if (terminal.consoleMessage) { if (terminal.consoleMessage) {
QH('p12TermConsoleMsg', EscapeHtml(terminal.consoleMessage).split('\n').join('<br />')); QH('p12TermConsoleMsg', EscapeHtml(terminal.consoleMessage).split('\n').join('<br />'));