Sync window title with the terminal

This commit is contained in:
Shuanglei Tao
2018-01-10 00:45:12 +08:00
parent 710aa1cd98
commit 2087fc6efe
2 changed files with 10 additions and 3 deletions

View File

@@ -147,7 +147,7 @@ var terminalContainer = document.getElementById('terminal-container'),
textEncoder = new TextEncoder(), textEncoder = new TextEncoder(),
authToken = (typeof tty_auth_token !== 'undefined') ? tty_auth_token : null, authToken = (typeof tty_auth_token !== 'undefined') ? tty_auth_token : null,
autoReconnect = -1, autoReconnect = -1,
term, pingTimer, wsError; term, pingTimer, title, wsError;
var openWs = function() { var openWs = function() {
var ws = new WebSocket(url, ['tty']); var ws = new WebSocket(url, ['tty']);
@@ -241,6 +241,12 @@ var openWs = function() {
}, 500); }, 500);
}); });
term.on('title', function (data) {
if (data && data !== '') {
document.title = (data + ' | ' + title);
}
});
term.on('data', sendData); term.on('data', sendData);
while (terminalContainer.firstChild) { while (terminalContainer.firstChild) {
@@ -273,7 +279,8 @@ var openWs = function() {
case '1': // pong case '1': // pong
break; break;
case '2': case '2':
document.title = textDecoder.decode(data); title = textDecoder.decode(data);
document.title = title;
break; break;
case '3': case '3':
var preferences = JSON.parse(textDecoder.decode(data)); var preferences = JSON.parse(textDecoder.decode(data));

2
src/index.html vendored

File diff suppressed because one or more lines are too long