Terminal / app /static /js /terminal.js
goingyt's picture
Update app/static/js/terminal.js
599878e verified
raw
history blame contribute delete
852 Bytes
document.addEventListener('DOMContentLoaded', function() {
const socket = io.connect('http://' + document.domain + ':' + location.port + '/terminal');
const input = document.getElementById('terminal-input');
const output = document.getElementById('terminal-output');
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const command = input.value;
output.innerHTML += `<div><span class="prompt">$</span> ${command}</div>`;
console.log(`Sending command: ${command}`); // Debugging log
socket.emit('input', {command: command});
input.value = '';
}
});
socket.on('output', function(data) {
console.log(`Received output: ${data.output}`); // Debugging log
output.innerHTML += `<div>${data.output}</div>`;
});
});