Late stage initialization for terminal support
This commit is contained in:
parent
56257e6f69
commit
95c7a857b9
@ -13,6 +13,19 @@
|
|||||||
term.loadAddon(fitAddon);
|
term.loadAddon(fitAddon);
|
||||||
var linkAddon = new WebLinksAddon();
|
var linkAddon = new WebLinksAddon();
|
||||||
term.loadAddon(linkAddon);
|
term.loadAddon(linkAddon);
|
||||||
|
var cxReadFunc = null;
|
||||||
|
function writeData(buf)
|
||||||
|
{
|
||||||
|
term.write(new Uint8Array(buf));
|
||||||
|
}
|
||||||
|
function readData(str)
|
||||||
|
{
|
||||||
|
if(cxReadFunc == null)
|
||||||
|
return;
|
||||||
|
for(var i=0;i<str.length;i++)
|
||||||
|
cxReadFunc(str.charCodeAt(i));
|
||||||
|
}
|
||||||
|
term.onData(readData);
|
||||||
function initTerminal()
|
function initTerminal()
|
||||||
{
|
{
|
||||||
const consoleDiv = document.getElementById("console");
|
const consoleDiv = document.getElementById("console");
|
||||||
@ -21,6 +34,15 @@
|
|||||||
fitAddon.fit();
|
fitAddon.fit();
|
||||||
window.addEventListener("resize", function(ev){ fitAddon.fit(); });
|
window.addEventListener("resize", function(ev){ fitAddon.fit(); });
|
||||||
term.focus();
|
term.focus();
|
||||||
|
// Avoid undesired default DnD handling
|
||||||
|
function preventDefaults (e) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
}
|
||||||
|
consoleDiv.addEventListener("dragover", preventDefaults, false);
|
||||||
|
consoleDiv.addEventListener("dragenter", preventDefaults, false);
|
||||||
|
consoleDiv.addEventListener("dragleave", preventDefaults, false);
|
||||||
|
consoleDiv.addEventListener("drop", preventDefaults, false);
|
||||||
initCheerpX();
|
initCheerpX();
|
||||||
}
|
}
|
||||||
async function initCheerpX()
|
async function initCheerpX()
|
||||||
@ -86,6 +108,9 @@
|
|||||||
// TODO: Print error message on console
|
// TODO: Print error message on console
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
// TODO: Register activity callbacks
|
||||||
|
term.scrollToBottom();
|
||||||
|
cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows);
|
||||||
}
|
}
|
||||||
onMount(initTerminal);
|
onMount(initTerminal);
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user