diff --git a/html/css/app.css b/html/css/app.css index fd2e5f7..c93c284 100644 --- a/html/css/app.css +++ b/html/css/app.css @@ -17,7 +17,7 @@ html, body { background-color: #101010; color: #f0f0f0; font-size: 10pt; - font-family: Menlo,Consolas,"DejaVu Sans Mono","Liberation Mono",Courier,monospace; + font-family: "Menlo for Powerline", Menlo,Consolas,"DejaVu Sans Mono","Liberation Mono",Courier,monospace; font-variant-ligatures: none; -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; diff --git a/html/index.html b/html/index.html index d252eaf..f67c919 100644 --- a/html/index.html +++ b/html/index.html @@ -9,7 +9,6 @@ -
diff --git a/html/js/app.js b/html/js/app.js index 47a732c..da25092 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -8,18 +8,30 @@ term, pingTimer, wsError; var openWs = function() { - var ws = new WebSocket(url, protocols); + var ws = new WebSocket(url, protocols), + textDecoder = new TextDecoder(), + textEncoder = new TextEncoder(); var unloadCallback = function(event) { var message = 'Close terminal? this will also terminate the command.'; (event || window.event).returnValue = message; return message; }; + var sendMessage = function (msg) { + if (ws.readyState === WebSocket.OPEN) { + ws.send(textEncoder.encode(msg)); + } + }; + var sendPing = function() { + sendMessage("1"); + }; - ws.onopen = function(event) { + ws.binaryType = 'arraybuffer'; + + ws.onopen = function() { console.log("Websocket connection opened"); wsError = false; - ws.send(JSON.stringify({AuthToken: authToken})); - pingTimer = setInterval(sendPing, 30 * 1000, ws); + sendMessage(JSON.stringify({AuthToken: authToken})); + pingTimer = setInterval(sendPing, 30 * 1000); if (typeof term !== 'undefined') { term.destroy(); @@ -28,18 +40,14 @@ term = new Terminal(); term.on('resize', function(size) { - if (ws.readyState === WebSocket.OPEN) { - ws.send("2" + JSON.stringify({columns: size.cols, rows: size.rows})); - } + sendMessage("2" + JSON.stringify({columns: size.cols, rows: size.rows})); setTimeout(function() { term.showOverlay(size.cols + 'x' + size.rows); }, 500); }); term.on("data", function(data) { - if (ws.readyState === WebSocket.OPEN) { - ws.send("0" + data); - } + sendMessage("0" + data); }); term.on('open', function() { @@ -62,10 +70,11 @@ }; ws.onmessage = function(event) { - var data = event.data.slice(1); - switch(event.data[0]) { + var cmd = String.fromCharCode(new DataView(event.data).getUint8()), + data = textDecoder.decode(event.data.slice(1)); + switch(cmd) { case '0': - term.writeUTF8(window.atob(data)); + term.write(data); break; case '1': // pong break; @@ -104,9 +113,5 @@ }; }; - var sendPing = function(ws) { - ws.send("1"); - }; - openWs(); })(); \ No newline at end of file diff --git a/html/js/utf8.js b/html/js/utf8.js deleted file mode 100644 index 5a10144..0000000 --- a/html/js/utf8.js +++ /dev/null @@ -1,118 +0,0 @@ -// ported from hterm.Terminal.IO.prototype.writeUTF8 -// https://chromium.googlesource.com/apps/libapps/+/master/hterm/js/hterm_terminal_io.js - -UTF8Decoder = function() { - this.bytesLeft = 0; - this.codePoint = 0; - this.lowerBound = 0; -}; - -UTF8Decoder.prototype.decode = function(str) { - var ret = ''; - for (var i = 0; i < str.length; i++) { - var c = str.charCodeAt(i); - if (this.bytesLeft == 0) { - if (c <= 0x7F) { - ret += str.charAt(i); - } else if (0xC0 <= c && c <= 0xDF) { - this.codePoint = c - 0xC0; - this.bytesLeft = 1; - this.lowerBound = 0x80; - } else if (0xE0 <= c && c <= 0xEF) { - this.codePoint = c - 0xE0; - this.bytesLeft = 2; - this.lowerBound = 0x800; - } else if (0xF0 <= c && c <= 0xF7) { - this.codePoint = c - 0xF0; - this.bytesLeft = 3; - this.lowerBound = 0x10000; - } else if (0xF8 <= c && c <= 0xFB) { - this.codePoint = c - 0xF8; - this.bytesLeft = 4; - this.lowerBound = 0x200000; - } else if (0xFC <= c && c <= 0xFD) { - this.codePoint = c - 0xFC; - this.bytesLeft = 5; - this.lowerBound = 0x4000000; - } else { - ret += '\ufffd'; - } - } else { - if (0x80 <= c && c <= 0xBF) { - this.bytesLeft--; - this.codePoint = (this.codePoint << 6) + (c - 0x80); - if (this.bytesLeft == 0) { - var codePoint = this.codePoint; - if (codePoint < this.lowerBound - || (0xD800 <= codePoint && codePoint <= 0xDFFF) - || codePoint > 0x10FFFF) { - ret += '\ufffd'; - } else { - if (codePoint < 0x10000) { - ret += String.fromCharCode(codePoint); - } else { - codePoint -= 0x10000; - ret += String.fromCharCode( - 0xD800 + ((codePoint >>> 10) & 0x3FF), - 0xDC00 + (codePoint & 0x3FF)); - } - } - } - } else { - ret += '\ufffd'; - this.bytesLeft = 0; - i--; - } - } - } - return ret; -}; - -Terminal.prototype.decodeUTF8 = function(str) { - return (new UTF8Decoder()).decode(str); -}; - -Terminal.prototype.encodeUTF8 = function(str) { - var ret = ''; - for (var i = 0; i < str.length; i++) { - var c = str.charCodeAt(i); - if (0xDC00 <= c && c <= 0xDFFF) { - c = 0xFFFD; - } else if (0xD800 <= c && c <= 0xDBFF) { - if (i+1 < str.length) { - var d = str.charCodeAt(i+1); - if (0xDC00 <= d && d <= 0xDFFF) { - c = 0x10000 + ((c & 0x3FF) << 10) + (d & 0x3FF); - i++; - } else { - c = 0xFFFD; - } - } else { - c = 0xFFFD; - } - } - var bytesLeft; - if (c <= 0x7F) { - ret += str.charAt(i); - continue; - } else if (c <= 0x7FF) { - ret += String.fromCharCode(0xC0 | (c >>> 6)); - bytesLeft = 1; - } else if (c <= 0xFFFF) { - ret += String.fromCharCode(0xE0 | (c >>> 12)); - bytesLeft = 2; - } else { - ret += String.fromCharCode(0xF0 | (c >>> 18)); - bytesLeft = 3; - } - while (bytesLeft > 0) { - bytesLeft--; - ret += String.fromCharCode(0x80 | ((c >>> (6 * bytesLeft)) & 0x3F)); - } - } - return ret; -}; - -Terminal.prototype.writeUTF8 = function (str) { - this.write(this.decodeUTF8(str)); -}; diff --git a/src/index.html b/src/index.html index d615286..56abdd5 100644 --- a/src/index.html +++ b/src/index.html @@ -6,18 +6,17 @@