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(),
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));