-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm.js
More file actions
67 lines (56 loc) · 1.82 KB
/
term.js
File metadata and controls
67 lines (56 loc) · 1.82 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
56
57
58
59
60
61
62
63
64
65
66
// script.js
const outputElement = document.getElementById('output');
const inputElement = document.getElementById('input');
// Command definitions
const commands = {
help: () => 'Available commands:\n\n' + Object.keys(commands).join('\n'),
ls: () => '. .. secret',
cat: (file) => {
return (file === "secret") ? `
/\\_/\\
( o o )
> ^ <` : 'Usage: cat <file>';
},
github: () => {
window.open("https://github.com/guizaa", "_blank");
return "Redirecting to Github...";
},
linkedin: () => {
window.open("https://www.linkedin.com/in/santiago-uribe-guiza-62b501235/", "_blank");
return "Redirecting to LinkedIn...";
},
resume: () => {
window.open("Santiago-Uribe-Guiza-Resume.pdf", "_blank");
return "Opening resume...";
}
};
// Function to handle command execution
function handleCommand(input) {
const [command, ...args] = input.trim().split(/\s+/);
if (commands[command]) {
return commands[command](...args);
} else {
return `Command not found: ${command}. Type 'help' for available commands.`;
}
}
// Display output in the terminal
function appendOutput(text) {
let newLine = $('<div></div>');
newLine.text(text);
newLine.insertBefore("#prompt-line");
outputElement.scrollTop = outputElement.scrollHeight; // Scroll to bottom
}
// Handle the Enter key press for command input
inputElement.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
const input = inputElement.value.trim();
// Append user command to output
appendOutput(`guest@guiza.dev:~$ ${input}`);
if (input === '') return;
// Execute and append the command's output
const output = handleCommand(input);
if (output) appendOutput(output);
// Clear the input field for the next command
inputElement.value = '';
}
});