-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsection.cli.php
61 lines (54 loc) · 1.3 KB
/
section.cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<style>
#cli-output {
width: 100%;
height: 300px;
background: black;
color: #0f0;
padding: 10px;
overflow-y: auto;
white-space: pre-wrap;
border: 1px solid #0f0;
font-family: monospace;
}
#cli-input {
width: 100%;
background: black;
color: #0f0;
border: none;
padding: 10px;
font-size: 16px;
font-family: monospace;
}
</style>
<div id="cli-output"></div>
<input type="text" id="cli-input" placeholder="Enter a command..." autofocus>
<script>
async function sendCommand(command) {
if (!command.trim()) return;
let outputDiv = $('#cli-output');
outputDiv.append(`> ${command}\n`);
$('#cli-input').val('');
try {
let response = await $.ajax({
url: '/api/cli_backend.php',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
command: command
})
});
outputDiv.append(response + "\n");
} catch (error) {
outputDiv.append("Error: " + error.statusText + "\n");
}
outputDiv.scrollTop(outputDiv[0].scrollHeight);
}
$(document).ready(() => {
$('#cli-input').keypress(async function(event) {
if (event.key === 'Enter') {
event.preventDefault();
await sendCommand($(this).val());
}
});
});
</script>