-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (114 loc) · 3.73 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Web CLI</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap" rel="stylesheet">
<style>
* {
font-family: Ubuntu, sans-serif;
}
body {
margin: 0;
padding: 0;
font-family: monospace;
background-color: #f8f9fa;
}
#terminal {
height: 80vh;
overflow-y: scroll;
background: black;
color: white;
padding: 10px;
border-radius: 5px;
position: relative;
}
#input {
width: 100%;
background: #343a40;
color: white;
border: none;
border-radius: 5px;
padding: 10px;
margin-top: 10px;
margin-bottom: 0;
}
#welcome-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
}
/* Adjust position for smaller screens */
@media (max-width: 768px) {
#welcome-text {
white-space: nowrap; /* Prevent text from wrapping */
}
}
#input:focus {
outline: none;
box-shadow: none;
}
</style>
</head>
<body>
<div class="container mt-4 mx-auto">
<div class="row justify-content-center">
<div class="col-md-12">
<div id="terminal" class="mb-3 text-white bg-dark text-light">
<div id="welcome-text" class="text-white font-weight-bold">Welcome to Web CLI!</div>
</div>
</div>
<div class="col-md-12">
<input type="text" id="input" class="form-control text-dark bg-white border border-dark" autofocus>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const terminal = document.getElementById('terminal');
const input = document.getElementById('input');
input.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
const welcomeText = document.getElementById('welcome-text');
if (welcomeText) {
welcomeText.style.display = 'none';
}
const command = input.value;
input.value = '';
executeCommand(command);
}
});
function executeCommand(command) {
const commandLine = document.createElement('div');
commandLine.textContent = '> ' + command;
commandLine.classList.add('text-white', 'font-weight-bold');
terminal.appendChild(commandLine);
fetch('/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ command: command })
})
.then(response => response.json())
.then(data => {
const output = document.createElement('div');
output.textContent = data.output;
output.classList.add('text-white');
terminal.appendChild(output);
terminal.scrollTop = terminal.scrollHeight;
});
}
});
</script>
</body>
</html>