mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
system: show what the console command printed
The console tab posts to /cmd and throws the response away, so the page stayed silent whether the command worked, was refused or was just misspelt. Now that /cmd answers with the command's output, the page keeps a running transcript: each command echoed after a prompt, then whatever it printed. The box is a pre element filled through textContent, so nothing the device prints is taken for markup. It scrolls to the newest line and the input clears after a send.
This commit is contained in:
1 parent
81af3a29a2
commit
f46ef3a43c
2 files changed
+9
-2
No files matched your search
+7
-2
@@ -35,14 +35,19 @@ async function ipSub() {
|
||||
}
|
||||
|
||||
async function cmdSub() {
|
||||
var cmd = document.getElementById('console_cmd').value;
|
||||
const input = document.getElementById('console_cmd');
|
||||
const out = document.getElementById('console_out');
|
||||
const cmd = input.value;
|
||||
try {
|
||||
const response = await fetch('/cmd', {
|
||||
method: 'POST',
|
||||
body: cmd
|
||||
});
|
||||
console.log('Completed!', response);
|
||||
out.textContent += "> " + cmd + "\n" + await response.text();
|
||||
out.scrollTop = out.scrollHeight;
|
||||
input.value = "";
|
||||
} catch(err) {
|
||||
out.textContent += "> " + cmd + "\n" + err + "\n";
|
||||
console.error(`Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user