From: Shuanglei Tao Date: Tue, 9 Jan 2018 16:45:12 +0000 (+0800) Subject: Sync window title with the terminal X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=2087fc6efe82c335ecf096321802f0237e9c8e98;p=ttyd.git Sync window title with the terminal --- diff --git a/html/js/app.js b/html/js/app.js index ecdfefe..8c3bb7a 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -147,7 +147,7 @@ var terminalContainer = document.getElementById('terminal-container'), textEncoder = new TextEncoder(), authToken = (typeof tty_auth_token !== 'undefined') ? tty_auth_token : null, autoReconnect = -1, - term, pingTimer, wsError; + term, pingTimer, title, wsError; var openWs = function() { var ws = new WebSocket(url, ['tty']); @@ -241,6 +241,12 @@ var openWs = function() { }, 500); }); + term.on('title', function (data) { + if (data && data !== '') { + document.title = (data + ' | ' + title); + } + }); + term.on('data', sendData); while (terminalContainer.firstChild) { @@ -273,7 +279,8 @@ var openWs = function() { case '1': // pong break; case '2': - document.title = textDecoder.decode(data); + title = textDecoder.decode(data); + document.title = title; break; case '3': var preferences = JSON.parse(textDecoder.decode(data)); diff --git a/src/index.html b/src/index.html index 6c0f172..1bdfcca 100644 --- a/src/index.html +++ b/src/index.html @@ -51,6 +51,6 @@ blockquote,body,dd,dl,dt,fieldset,figure,h1,h2,h3,h4,h5,h6,hr,html,iframe,legend - +