Update app/static/js/terminal.js
Browse files
app/static/js/terminal.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
document.addEventListener('DOMContentLoaded', function() {
|
|
|
2 |
const input = document.getElementById('terminal-input');
|
3 |
const output = document.getElementById('terminal-output');
|
4 |
|
@@ -6,15 +7,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
6 |
if (e.key === 'Enter') {
|
7 |
const command = input.value;
|
8 |
output.innerHTML += `<div><span class="prompt">$</span> ${command}</div>`;
|
9 |
-
|
10 |
-
// Add basic command handling here
|
11 |
-
if (command === 'clear') {
|
12 |
-
output.innerHTML = '';
|
13 |
-
} else {
|
14 |
-
output.innerHTML += `<div>Command not found: ${command}</div>`;
|
15 |
-
}
|
16 |
-
|
17 |
input.value = '';
|
18 |
}
|
19 |
});
|
|
|
|
|
|
|
|
|
20 |
});
|
|
|
1 |
document.addEventListener('DOMContentLoaded', function() {
|
2 |
+
const socket = io.connect('http://' + document.domain + ':' + location.port + '/terminal');
|
3 |
const input = document.getElementById('terminal-input');
|
4 |
const output = document.getElementById('terminal-output');
|
5 |
|
|
|
7 |
if (e.key === 'Enter') {
|
8 |
const command = input.value;
|
9 |
output.innerHTML += `<div><span class="prompt">$</span> ${command}</div>`;
|
10 |
+
socket.emit('input', {command: command});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
input.value = '';
|
12 |
}
|
13 |
});
|
14 |
+
|
15 |
+
socket.on('output', function(data) {
|
16 |
+
output.innerHTML += `<div>${data.output}</div>`;
|
17 |
+
});
|
18 |
});
|