This commit is contained in:
ACoolName 2024-06-02 22:32:43 +03:00
parent ea22c5c594
commit ada3f67689

View File

@ -286,48 +286,45 @@ export function ActionItem(p: { action: ActionInfo, identifierSubstring?: string
<body>
<div id="root"></div>
<script>
const terminalContainer = document.getElementById('root');
window.onload = function() {
const terminalContainer = document.getElementById('root');
const terminal = new Terminal();
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
terminal.open(terminalContainer);
fitAddon.fit();
const terminal = new Terminal();
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
terminal.open(terminalContainer);
fitAddon.fit();
if (websocket) {
const socket = new WebSocket("`+websocket+`");
if (websocket) {
const socket = new WebSocket("`+websocket+`");
socket.onerror = (ev) => {
console.log(ev);
};
socket.onerror = (ev) => {
console.log(ev);
};
socket.addEventListener('open', () => {
socket.send(JSON.stringify({ CommandType: 'resize', Arguments: \`\${terminal.cols}x\${terminal.rows}\` }));
});
terminal.onResize(({ cols, rows }) => {
socket.send(JSON.stringify({ CommandType: 'resize', Arguments: \`\${cols}x\${rows}\` }));
});
socket.addEventListener('message', (event) => {
terminal.write(JSON.parse(event.data));
});
terminal.onData((data) => {
socket.send(JSON.stringify({ CommandType: 'insert', Arguments: data }));
});
window.addEventListener('beforeunload', () => {
socket.close();
});
}
window.addEventListener('resize', () => {
fitAddon.fit();
socket.addEventListener('open', () => {
socket.send(JSON.stringify({ CommandType: 'resize', Arguments: \`\${terminal.cols}x\${terminal.rows}\` }));
});
};
terminal.onResize(({ cols, rows }) => {
socket.send(JSON.stringify({ CommandType: 'resize', Arguments: \`\${cols}x\${rows}\` }));
});
socket.addEventListener('message', (event) => {
terminal.write(JSON.parse(event.data));
});
terminal.onData((data) => {
socket.send(JSON.stringify({ CommandType: 'insert', Arguments: data }));
});
window.addEventListener('beforeunload', () => {
socket.close();
});
}
window.addEventListener('resize', () => {
fitAddon.fit();
});
</script>
</body>
</html>