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> <body>
<div id="root"></div> <div id="root"></div>
<script> <script>
const terminalContainer = document.getElementById('root');
window.onload = function() { const terminal = new Terminal();
const terminalContainer = document.getElementById('root'); const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
const terminal = new Terminal(); terminal.open(terminalContainer);
const fitAddon = new FitAddon(); fitAddon.fit();
terminal.loadAddon(fitAddon);
terminal.open(terminalContainer);
fitAddon.fit();
if (websocket) { if (websocket) {
const socket = new WebSocket("`+websocket+`"); const socket = new WebSocket("`+websocket+`");
socket.onerror = (ev) => { socket.onerror = (ev) => {
console.log(ev); console.log(ev);
}; };
socket.addEventListener('open', () => { socket.addEventListener('open', () => {
socket.send(JSON.stringify({ CommandType: 'resize', Arguments: \`\${terminal.cols}x\${terminal.rows}\` })); 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();
}); });
};
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> </script>
</body> </body>
</html> </html>