-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (46 loc) · 1.45 KB
/
Copy pathscript.js
File metadata and controls
55 lines (46 loc) · 1.45 KB
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
const terminal = document.getElementById('terminal');
const commandInput = document.getElementById('commandInput');
commandInput.addEventListener('keyup', function (event) {
if (event.key === 'Enter') {
executeCommand(commandInput.value.trim());
}
});
function executeCommand(command) {
const output = document.createElement('p');
output.textContent = `$ ${command}`;
terminal.querySelector('.output').appendChild(output);
switch (command.toLowerCase()) {
case 'help':
printHelp();
break;
case 'clear':
clearTerminal();
break;
default:
printError(`Command not found: ${command}`);
}
commandInput.value = '';
terminal.scrollTop = terminal.scrollHeight;
}
function printHelp() {
const helpText = [
'Available Commands:',
'- help: Display this help message.',
'- clear: Clear the terminal screen.'
];
helpText.forEach(text => printOutput(text));
}
function clearTerminal() {
terminal.querySelector('.output').innerHTML = '';
}
function printOutput(text) {
const output = document.createElement('p');
output.textContent = text;
terminal.querySelector('.output').appendChild(output);
}
function printError(message) {
const error = document.createElement('p');
error.style.color = '#ff0000';
error.textContent = `Error: ${message}`;
terminal.querySelector('.output').appendChild(error);
}