-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
138 lines (118 loc) · 3.04 KB
/
Copy pathindex.html
File metadata and controls
138 lines (118 loc) · 3.04 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>user@host:~$</title>
<style>
body {
background: #1e1e1e;
color: #c5c5c5;
font-family: monospace;
margin: 0;
padding: 20px;
}
#terminal {
background: #111;
border: 1px solid #333;
height: 400px;
padding: 10px;
overflow-y: auto;
}
.line {
display: flex;
align-items: center;
margin-bottom: 2px;
}
.prompt {
margin-right: 5px;
}
.input {
background: transparent;
border: none;
outline: none;
color: #c5c5c5;
font-family: monospace;
flex: 1;
font-size: 16px;
}
.disabled {
color: #888;
}
</style>
</head>
<body>
<div id="terminal"></div>
<script>
const terminal = document.getElementById('terminal');
let cwd = "~";
let hostname = "arch";
let user = "root";
function display(text) {
const line = document.createElement("div");
line.textContent = text;
terminal.appendChild(line);
terminal.scrollTop = terminal.scrollHeight;
}
function newPrompt() {
const line = document.createElement("div");
line.className = "line";
const prompt = document.createElement("span");
prompt.className = "prompt";
prompt.textContent = `${user}@${hostname}:${cwd}#`;
updateTitle();
function updateTitle() {
document.title = `${user}@${hostname}:${cwd}#`;
}
const input = document.createElement("input");
input.className = "input";
input.autocomplete = "off";
input.autofocus = true;
input.spellcheck = false;
line.appendChild(prompt);
line.appendChild(input);
terminal.appendChild(line);
input.focus();
input.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
const cmd = input.value.trim();
input.disabled = true;
input.classList.add("disabled");
execute(cmd);
}
});
terminal.scrollTop = terminal.scrollHeight;
}
function execute(cmd) {
if(cmd === "cd .." && cwd === "~") cwd = "/";
else if(cmd === "cd") cwd = "~";
else if(cmd === "ls" && cwd === "~") display("file.txt");
else if(cmd === "ls" && cwd === "/") display(
`bin etc lib linuxrc mnt proc run sys usr
dev home lib64 media opt root sbin tmp var`
);
else if(cmd==="cat ~/file.txt") display("foobars");
else if(cmd === "cd /") cwd = "/";
else if(cmd === "ls /") display(
`bin etc lib linuxrc mnt proc run sys usr
dev home lib64 media opt root sbin tmp var`
);
else if(cmd === "clear") {
terminal.innerHTML = ""; // clears all output
newPrompt(); // show a fresh prompt
return; // stop further execution
}
else if(cmd === "exit") {
display("logout.");
return;
}
else display(`sh: ${cmd.split(" ")[0]}: command not found or invalid arguments`);
newPrompt();
}
// Initialize terminal
display("Booting...");
display("Welcome to arch!");
newPrompt(); //your amazing
</script>
</body>
</html>