-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.js
289 lines (257 loc) · 7.11 KB
/
terminal.js
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// terminal command router
// terminal command functions
_clear = () => {
displayelem.innerHTML = "";
_pastbuff = _prompt;
_ibuff = [];
};
_date = () => {
_print(new Date().toISOString());
};
const help_ = `
<pre>
"help This command",
"about Brief summary about myself"
"skills Skillset, and what tools I use"
"contact How to contact to me",
"contact <key> Open page (example: 'email' or 'linkedin')",
"clear Clears the screen",
"play RetroWave animation with sound"
"night Css only animation"
"turbine Yet another css only animation"
"spaceinv Space Invaders written in js"
"google84 Google landing page if its invented in the 80s"
"letitsnow Merry Christmas"
</pre>`;
const about_ = `
<pre>
Janos Lengyel, senior software engineer.
Mainly working on frontend using [Angular], [Vue], [React]
and javascript, css(3), html.
Always eager to learn new technologies.
<b>LEVEL:</b> 5+ years of experience
<b>PERSONALITY:</b> quiet, curious, calm, analytical
<b>SKILLS:</b> front-end, back-end, devops, ux/ui
<b>INTERESTS:</b> programming, old games, podcasts, travel, reading, learning, cats
</pre>`;
const skills_ = `
<pre>
Web applications Angular
Creativity NPM
Javascript Node.js
CSS Linux
Python Vue
UX/UI React
</pre>`;
const contact_ = `
<pre>
"[email]: <a href="mailto:[email protected]">[email protected]"</a>
"[linkedin]: <a href='https://www.linkedin.com/in/janoslengyel/' target=_blank>janoslengyel</a>",
"[soundcloud]: <a href="https://soundcloud.com/p0lish" target=_blank>p0lish</a>",
"[github]: <a href="https://github.com/p0lish" target=_blank >https://github.com/p0lish</a>",
</pre>`;
_help = () => {
_print(help_);
};
_about = () => {
_print(about_);
};
_skills = () => {
_print(skills_);
};
_play = () => {
window.open("/nrw.html");
};
_night = () => {
window.open("/night");
}
_turbine = () => {
window.open("/wind-turbine");
}
_spaceinvaders = () => {
window.open("/spaceinvaders");
}
_google84 = () => {
window.open("/google84");
}
_letitsnow = () => {
window.open("/christmas2021");
}
_contact = param => {
const contacts = {
email: "mailto:[email protected]",
linkedin: "https://www.linkedin.com/in/janoslengyel/",
soundcloud: "https://soundcloud.com/p0lish",
github: "https://github.com/p0lish"
};
if (param && Object.keys(contacts).includes(param)) {
window.open(contacts[param]);
} else {
_print(contact_);
}
};
_terminalfunctions = {
clear: _clear,
cls: _clear,
date: _date,
help: _help,
contact: _contact,
about: _about,
skills: _skills,
play: _play,
night: _night,
turbine: _turbine,
spaceinv: _spaceinvaders,
invaders: _spaceinvaders,
space: _spaceinvaders,
google84: _google84,
letitsnow: _letitsnow
};
(() => {
// initial configuration
displayelem = document.querySelector("#display");
clielem = document.querySelector("#input");
_prompt = "<b class='prompt'>p0lish:~$ </b> "; // type of the prompt
cursor = "<span class='cursor'>█</span>"; // cursor element
unknowncommand = "Unknown command";
linebreak = "<br />";
linebreaks = "<br /><br />";
_pastbuff = "";
_ibuff = [];
_cursorSpeed = 10;
readonly = false;
// render buffer contents to the display
_render = () => (clielem.innerHTML = _pastbuff + _ibuff.join("") + cursor);
_freeze = () => {
displayelem.innerHTML += _pastbuff + linebreak;
_pastbuff = "";
_ibuff = [];
};
_nbspline = () => (_pastbuff += _ibuff.join("").concat(_prompt));
_newline = () => (_pastbuff += _ibuff.join("").concat(linebreak, _prompt));
_newlines = () => (_pastbuff += _ibuff.join("").concat(linebreaks, _prompt));
_print = buff => {
readonly = true;
_pastbuff += _ibuff.join("").concat(linebreak);
let i = 0;
const timer = setInterval(() => {
if (i > buff.length - 1) {
_freeze();
_nbspline();
clearInterval(timer);
readonly = false;
} else {
_pastbuff += buff[i];
}
_render();
window.scrollTo(0, document.body.scrollHeight);
i++;
}, _cursorSpeed);
};
_put = buff => {
_pastbuff += linebreak;
_pastbuff += buff;
_ibuff = [];
_freeze();
window.scrollTo(0, document.body.scrollHeight);
};
_initBanner = () => {
_print(`<pre>
Basic retro look terminal emulator written in js, and also a brief resume about me.
type 'help' for more information
</pre>`);
};
// command router
_commands = {
Backspace: () => {
_ibuff = _ibuff.splice(0, _ibuff.length - 1);
},
Enter: () => {
const input = _ibuff.join("").split(" ")[0];
const param = _ibuff.join("").split(" ")[1];
if (Object.keys(_terminalfunctions).includes(input)) {
_terminalfunctions[input](param);
} else if (_ibuff.length < 1) {
_freeze();
_nbspline();
} else {
_pastbuff += _ibuff
.join("")
.concat(
linebreak,
unknowncommand,
" '",
_ibuff.join(""),
"'",
linebreaks,
_prompt
);
}
_ibuff = [];
window.scrollTo(0, document.body.scrollHeight);
},
AltLeft: () => false,
AltRight: () => false,
ShiftLeft: () => false,
ShiftRight: () => false,
ControlLeft: () => false,
ControlRight: () => false,
ArrowUp: () => false,
ArrowDown: () => false,
ArrowLeft: () => false,
ArrowRight: () => false,
F1: () => false,
F2: () => false,
F3: () => false,
F4: () => false,
F5: () => false,
F6: () => false,
F7: () => false,
F8: () => false,
F9: () => false,
F10: () => false,
F11: () => false,
F12: () => false,
Escape: () => false,
Insert: () => false,
Delete: () => false,
Home: () => false,
End: () => false,
PageUp: () => false,
PageDown: () => false,
CapsLock: () => false,
Tab: () => false,
MetaLeft: () => false,
MetaRight: () => false,
Pause: () => false,
ScrollLock: () => false,
Meta: () => false,
};
_preFormatChar = char => {
const charMap = {
"<": "<",
">": ">",
" ": " "
};
_lastchar = char;
return charMap[char] || char;
};
// terminal initialzer
init = () => {
_initBanner();
window.addEventListener("keydown", event => {
if (!readonly) {
code = event.code || event.which;
if (Object.keys(_commands).includes(code)) {
_commands[code](_ibuff.join(""));
} else {
_ibuff.push(_preFormatChar(event.key));
}
_render();
}
});
_render();
window.scrollTo(0, document.body.scrollHeight);
};
init();
})();