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>`; | |
}); | |
}); |