forked from y8tireu/Terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
189 lines (176 loc) · 6.37 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Full-Screen Terminal</title>
<style>
body {
margin: 0;
font-family: monospace;
background-color: #121212;
color: #00aaff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
overflow: hidden;
}
#terminal {
width: 100%;
height: 100%;
background: #000;
padding: 10px;
overflow-y: auto;
box-sizing: border-box;
}
#output {
white-space: pre-wrap;
word-wrap: break-word;
}
#input-container {
display: flex;
align-items: center;
}
#input-container span {
margin-right: 5px;
color: #00aaff;
}
#input {
flex: 1;
background: transparent;
border: none;
color: #00aaff;
font-family: monospace;
font-size: 16px;
outline: none;
}
</style>
</head>
<body>
<div id="terminal">
<div id="output" role="log" aria-live="polite"></div>
<div id="input-container">
<span>y8tireu@archlinux:</span>
<input type="text" id="input" autocomplete="off" autofocus aria-label="Terminal input">
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const output = document.getElementById("output");
const input = document.getElementById("input");
let currentDirectory = "/";
let files = { "/": {} };
const commands = {
help: () => `
Available commands:
help - Show this help message
clear - Clear the terminal screen
ls - List files in the current directory
cd <dir> - Change directory
mkdir <dir> - Create a new directory
touch <file> - Create a new file
rm <file> - Remove a file
rmdir <dir> - Remove an empty directory
echo <text> - Print text to the terminal
neofetch - Display system information
pwd - Print the current directory
whoami - Display the current user
exit - Exit the terminal (simulated)
`,
clear: () => {
output.innerHTML = "";
return "";
},
ls: () => Object.keys(files[currentDirectory] || {}).join("\n") || "(empty)",
cd: (dir) => {
if (dir === "..") {
const parts = currentDirectory.split("/");
parts.pop();
currentDirectory = parts.join("/") || "/";
} else {
const newDir = currentDirectory === "/" ? `/${dir}` : `${currentDirectory}/${dir}`;
if (files[newDir] && typeof files[newDir] === "object") {
currentDirectory = newDir;
} else {
return `Directory not found: ${dir}`;
}
}
return `Current directory: ${currentDirectory}`;
},
mkdir: (dir) => {
const path = currentDirectory === "/" ? `/${dir}` : `${currentDirectory}/${dir}`;
if (!files[path]) {
files[path] = {};
return `Directory created: ${dir}`;
}
return `Directory already exists: ${dir}`;
},
touch: (file) => {
if (!files[currentDirectory]) files[currentDirectory] = {};
if (!files[currentDirectory][file]) {
files[currentDirectory][file] = "";
return `File created: ${file}`;
}
return `File already exists: ${file}`;
},
rm: (file) => {
if (files[currentDirectory] && files[currentDirectory][file]) {
delete files[currentDirectory][file];
return `File deleted: ${file}`;
}
return `No such file: ${file}`;
},
rmdir: (dir) => {
const path = currentDirectory === "/" ? `/${dir}` : `${currentDirectory}/${dir}`;
if (files[path] && typeof files[path] === "object" && Object.keys(files[path]).length === 0) {
delete files[path];
return `Directory deleted: ${dir}`;
}
return `Directory not empty or does not exist: ${dir}`;
},
echo: (...args) => args.join(" "),
neofetch: () => `
y8tireu@archlinux
----------------
OS: Arch Linux
Host: Github Enterprise Cloud
Kernel: 6.12
Uptime: 2 hours, 34 minutes
Packages: 2154
Shell: bash 5.1
Resolution: 3840x2160
CPU: AMD Ryzen 7 9700X
GPU: AMD Radeon RX 7900 XTX
Memory: 1GB / 128GB
`,
pwd: () => `Current directory: ${currentDirectory}`,
whoami: () => "user",
exit: () => {
appendOutput("Exiting terminal... Goodbye!");
input.disabled = true;
return "";
},
};
input.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
const userInput = input.value.trim();
if (!userInput) return;
const [command, ...args] = userInput.split(" ");
const result =
commands[command] !== undefined
? commands[command](...args)
: `Command not found: ${command}`;
appendOutput(`> ${userInput}\n${result}`);
input.value = ""; // Clear the input field
}
});
function appendOutput(text) {
output.innerHTML += `${text}\n`;
output.scrollTop = output.scrollHeight; // Auto-scroll to the bottom
}
});
</script>
</body>
</html>