[pve-devel] [PATCH xtermjs 3/3] use new Uint8Array interface of xterm.js
Dominik Csapak
d.csapak at proxmox.com
Tue Jan 21 15:38:29 CET 2020
which means we can drop our utf8-decoder
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/www/main.js | 4 ++--
src/www/util.js | 51 -------------------------------------------------
2 files changed, 2 insertions(+), 53 deletions(-)
diff --git a/src/www/main.js b/src/www/main.js
index 6d7ee69..49d382c 100644
--- a/src/www/main.js
+++ b/src/www/main.js
@@ -144,11 +144,11 @@ function createTerminal() {
function runTerminal() {
socket.onmessage = function(event) {
- var answer = Utf8ArrayToStr(event.data);
+ var answer = new Uint8Array(event.data);
if (state === states.connected) {
term.write(answer);
} else if(state === states.connecting) {
- if (answer.slice(0,2) === "OK") {
+ if (answer[0] === 79 && answer[1] === 75) { // "OK"
updateState(states.connected);
term.write(answer.slice(2));
} else {
diff --git a/src/www/util.js b/src/www/util.js
index fc6ef07..52cad21 100644
--- a/src/www/util.js
+++ b/src/www/util.js
@@ -69,57 +69,6 @@ function getQueryParameter(name) {
return result;
}
-var cur = 0;
-var left = 0;
-
-function Utf8ArrayToStr(arraybuffer) {
- var array = new Uint8Array(arraybuffer),
- i = 0,
- len = array.byteLength,
- out = "",
- c;
-
- while (i < len) {
- c = array[i++];
- if (!left && c < 0x80) {
- out += String.fromCharCode(c);
- } else if(!left) {
- switch (c >> 4) {
- case 12: case 13:
- // 110x xxxx 10xx xxxx
- cur = (c & 0x1F) << 6;
- left = 1;
- break;
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- cur = (c & 0x0F) << 12;
- left = 2;
- break;
- case 15:
- // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
- cur = (c & 0x07) << 18;
- left = 3;
- break;
- default:
- cur = 0;
- out += '\ufffd';
- }
- } else if (c >= 0x80 && c <= 0xBF) {
- cur = cur | ((c & 0x3F) << (--left * 6));
- if (!left) {
- out += String.fromCharCode(cur);
- cur = 0;
- }
- } else {
- cur = 0;
- left = 0;
- out += '\ufffd';
- }
- }
-
- return out;
-}
-
function API2Request(reqOpts) {
var me = this;
--
2.20.1
More information about the pve-devel
mailing list