[pve-devel] [PATCH xtermjs 2/3] adapt main.js to upstream xterm.js changes

Dominik Csapak d.csapak at proxmox.com
Tue Jan 21 15:38:28 CET 2020


Addon loading/usage changed
event listener interface changed ('on' to 'onResize', 'onData', etc.)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/www/Makefile          |  3 ++-
 src/www/index.html.tpl.in |  2 +-
 src/www/main.js           | 22 +++++++++++++---------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/www/Makefile b/src/www/Makefile
index a9effb0..5e51258 100644
--- a/src/www/Makefile
+++ b/src/www/Makefile
@@ -1,7 +1,8 @@
 WWWBASEDIR=${DESTDIR}/usr/share/pve-xtermjs
 
 SOURCE = \
-	addons/fit/fit.js \
+	xterm-addon-fit.js \
+	xterm-addon-fit.js.map \
 	index.html.tpl \
 	main.js \
 	style.css \
diff --git a/src/www/index.html.tpl.in b/src/www/index.html.tpl.in
index 8cc74ed..5002035 100644
--- a/src/www/index.html.tpl.in
+++ b/src/www/index.html.tpl.in
@@ -5,7 +5,7 @@
 	<link rel="stylesheet" href="/xtermjs/xterm.css?version=@VERSION@" />
 	<link rel="stylesheet" href="/xtermjs/style.css?version=@VERSION@" />
 	<script src="/xtermjs/xterm.js?version=@VERSION@" ></script>
-	<script src="/xtermjs/fit.js?version=@VERSION@" ></script>
+	<script src="/xtermjs/xterm-addon-fit.js?version=@VERSION@" ></script>
 	<script src="/xtermjs/util.js?version=@VERSION@" ></script>
     </head>
     <body>
diff --git a/src/www/main.js b/src/www/main.js
index 6a1dba3..6d7ee69 100644
--- a/src/www/main.js
+++ b/src/www/main.js
@@ -85,14 +85,15 @@ function updateState(newState, msg) {
 
 var terminalContainer = document.getElementById('terminal-container');
 document.getElementById('status_bar').addEventListener('click', hideMsg);
-Terminal.applyAddon(fit);
+const fitAddon = new FitAddon.FitAddon();
 
 createTerminal();
 
 function createTerminal() {
     term = new Terminal(getTerminalSettings());
+    term.loadAddon(fitAddon);
 
-    term.on('resize', function (size) {
+    term.onResize(function (size) {
 	if (state === states.connected) {
 	    socket.send("1:" + size.cols + ":" + size.rows + ":");
 	}
@@ -156,7 +157,7 @@ function runTerminal() {
 	}
     };
 
-    term.on('data', function(data) {
+    term.onData(function(data) {
 	if (state === states.connected) {
 	    socket.send("0:" + unescape(encodeURIComponent(data)).length.toString() + ":" +  data);
 	}
@@ -170,7 +171,7 @@ function runTerminal() {
 	clearTimeout(resize);
 	resize = setTimeout(function() {
 	    // done resizing
-	    term.fit();
+	    fitAddon.fit();
 	}, 250);
     });
 
@@ -179,7 +180,7 @@ function runTerminal() {
     // initial focus and resize
     setTimeout(function() {
 	term.focus();
-	term.fit();
+	fitAddon.fit();
     }, 250);
 }
 
@@ -286,10 +287,14 @@ function tryReconnect() {
     setTimeout(checkMigration, 5000);
 }
 
+function clearEvents() {
+    term.onResize(() => {});
+    term.onData(() => {});
+}
+
 function stopTerminal(event) {
     event = event || {};
-    term.off('resize');
-    term.off('data');
+    clearEvents();
     clearInterval(ping);
     socket.close();
     updateState(states.disconnected, event.msg + event.code);
@@ -297,8 +302,7 @@ function stopTerminal(event) {
 
 function errorTerminal(event) {
     even = event || {};
-    term.off('resize');
-    term.off('data');
+    clearEvents();
     clearInterval(ping);
     socket.close();
     term.dispose();
-- 
2.20.1





More information about the pve-devel mailing list