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
@@ -88,6 +88,8 @@
|
||||
<input style="width:20%;" class="action" id="cmd_sub" onclick="cmdSub();" type="button" data-i18n="sys_send_cmd" value="Send Command"><br/>
|
||||
<br/><br/>
|
||||
<span data-i18n="sys_console_warn">Be careful when entering console commands, you can lock yourself out!</span><br/>
|
||||
<br/>
|
||||
<pre id="console_out" style="height:22em;overflow:auto;white-space:pre-wrap;border:1px solid;padding:0.5em;"></pre>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
+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