Add recreate terminal after disposing to the demo

This commit is contained in:
Bruno Ribeito
2018-07-01 18:56:58 +01:00
parent 1395b0f03c
commit 054592520e
+17 -9
View File
@@ -50,6 +50,23 @@ addDomListener(actionElements.findPrevious, 'keypress', function (e) {
}
});
const disposeRecreateButtonHandler = () => {
// If the terminal exists dispose of it, otherwise recreate it
if (term) {
term.dispose();
term = null;
window.term = null;
socket = null;
document.getElementById('dispose').innerHTML = 'Recreate Terminal';
}
else {
createTerminal();
document.getElementById('dispose').innerHTML = 'Dispose terminal';
}
};
document.getElementById('dispose').addEventListener('click', disposeRecreateButtonHandler);
function createTerminal() {
// Clean terminal
while (terminalContainer.children.length) {
@@ -76,15 +93,6 @@ function createTerminal() {
term.fit();
term.focus();
const buttonHandler = () => {
term.dispose();
term = null;
window.term = null;
socket = null;
document.getElementById('dispose').removeEventListener('click', buttonHandler);
};
document.getElementById('dispose').addEventListener('click', buttonHandler);
// fit is called within a setTimeout, cols and rows need this.
setTimeout(function () {
initOptions(term);