-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.js
More file actions
408 lines (347 loc) · 16.1 KB
/
Copy pathterminal.js
File metadata and controls
408 lines (347 loc) · 16.1 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/**
* Interactive Developer Terminal
* A fake CLI for exploring Fidel Isaboke's portfolio.
*/
(function () {
'use strict';
const HISTORY_KEY = 'terminal-history';
const VISITED_KEY = 'terminal-visited';
const PROMPT = 'fidel@portfolio:~$ ';
const ASCII_BANNER = `
-----------------------------------------------
FIDEL ISABOKE | Full Stack Developer & AI Engineer
-----------------------------------------------
`;
const WELCOME_MSG = "\nWelcome to my interactive terminal. Type 'help' to get started.\n";
// Command Registry
const commands = {
help: () => {
return [
'',
' Available Commands:',
' ──────────────────────────────────────────────',
' about Who I am',
' skills My tech stack',
' projects Featured work',
' certifications Credentials & badges',
' contact How to reach me',
' cv Open my resume (new tab)',
' theme [d/l] Toggle or set the site theme',
' history Show command history',
' whoami Who are you?',
' date Current date & time',
' echo [text] Echo your input',
' clear Clear the terminal',
' secret ???',
' help Show this list',
'',
].join('\n');
},
about: () => {
return [
'',
' ╭──────────────────────────────────────────────╮',
' │ Fidel Isaboke │',
' │ Full Stack Developer & AI Engineer │',
' ╰──────────────────────────────────────────────╯',
'',
' Informatics & Computer Science graduate from',
' Strathmore University with 3+ years of experience',
' in web development. I build AI agents with LangChain',
' and deploy full-stack production systems.',
'',
' → <a href="about.html">Visit the About page</a>',
'',
].join('\n');
},
skills: () => {
return [
'',
' ┌─ Languages ──────────────────────────────────┐',
' │ Python · JavaScript · TypeScript │',
' └──────────────────────────────────────────────┘',
' ┌─ Frameworks ─────────────────────────────────┐',
' │ React · Next.js · FastAPI · Django · Flask │',
' └──────────────────────────────────────────────┘',
' ┌─ AI / ML ───────────────────────────────────-┐',
' │ LangChain · LangGraph · Scikit-Learn │',
' └──────────────────────────────────────────────┘',
' ┌─ Tools ──────────────────────────────────────┐',
' │ Git · Docker · PostgreSQL · MongoDB · Redis │',
' └──────────────────────────────────────────────┘',
'',
].join('\n');
},
projects: () => {
return [
'',
' Projects',
' ──────────────────────────────────────────────',
' Slideia AI slides generator <a href="https://slideia.vercel.app" target="_blank">↗ Demo</a> <a href="https://github.com/Fidelisaboke/slideia" target="_blank">↗ GitHub</a>',
' Zerra Code Rev. Socratic AI code reviewer <a href="https://github.com/apps/zerra-edtech-ai-code-reviewer" target="_blank">↗ App</a>',
' CreditExplain Self-RAG for compliance <a href="https://github.com/Fidelisaboke/CreditExplain" target="_blank">↗ GitHub</a>',
' Robust NIDS Adversarial ML defence <a href="https://github.com/Fidelisaboke/robust-nids" target="_blank">↗ GitHub</a>',
' StrathPort School transport system <a href="https://strathport.onrender.com" target="_blank">↗ Demo</a> <a href="https://github.com/Fidelisaboke/StrathPort" target="_blank">↗ GitHub</a>',
' Cannon Frenzy 2D Artillery game <a href="https://github.com/Fidelisaboke/cannon-frenzy-relaunched" target="_blank">↗ GitHub</a>',
'',
' → <a href="projects.html">View all projects</a>',
'',
].join('\n');
},
certifications: () => {
return [
'',
' Certifications',
' ──────────────────────────────────────────────',
' Introduction to AI Agents NSK.AI · 2025',
' Software Architecture Safaricom · 2024',
' Python Essentials 2 Cisco · 2024',
' CCNA: Switching & Routing Cisco · 2023',
' Python Essentials 1 Cisco · 2023',
' CCNA: Intro to Networks Cisco · 2023',
'',
' → <a href="about.html#certifications">View certificates</a>',
'',
].join('\n');
},
contact: () => {
return [
'',
' Get in Touch',
' ──────────────────────────────────────────────',
' GitHub <a href="https://github.com/Fidelisaboke" target="_blank">github.com/Fidelisaboke</a>',
' LinkedIn <a href="https://www.linkedin.com/in/fidel-isaboke-57aba3263/" target="_blank">linkedin.com/in/fidel-isaboke</a>',
'',
' → <a href="contact.html">Contact page</a>',
'',
].join('\n');
},
cv: () => {
if (window.trackEvent) {
window.trackEvent('Download CV', { location: 'terminal' });
}
window.open('docs/fidel-isaboke-cv.pdf', '_blank');
return '\n Opening resume in a new tab...\n';
},
theme: (args) => {
const arg = (args[0] || '').toLowerCase();
let next;
if (arg === 'd' || arg === 'dark') {
next = 'dark';
} else if (arg === 'l' || arg === 'light') {
next = 'light';
} else {
const current = document.documentElement.getAttribute('data-theme');
next = current === 'dark' ? 'light' : 'dark';
}
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('portfolio-theme', next);
return `\n Theme set to ${next}.\n`;
},
whoami: () => {
return '\n visitor@fidel-portfolio\n';
},
date: () => {
return '\n ' + new Date().toString() + '\n';
},
echo: (args) => {
return '\n ' + (args.join(' ') || '') + '\n';
},
clear: () => {
return '__CLEAR__';
},
history: () => {
const hist = JSON.parse(localStorage.getItem(HISTORY_KEY) || '[]');
if (hist.length === 0) return '\n No command history yet.\n';
const lines = hist.map((cmd, i) => ` ${String(i + 1).padStart(4)} ${cmd}`);
return '\n' + lines.join('\n') + '\n';
},
secret: () => {
return [
'',
' You found something...',
' There are hidden surprises in this terminal.',
' Try the Konami code (↑↑↓↓←→←→BA) sometime...',
'',
].join('\n');
},
sudo: () => {
return '\n Nice try. You don\'t have root access here.\n';
},
};
// Terminal Engine
let commandHistory = JSON.parse(localStorage.getItem(HISTORY_KEY) || '[]');
let historyIndex = -1;
function saveHistory() {
// Keep last 50 commands
const trimmed = commandHistory.slice(-50);
localStorage.setItem(HISTORY_KEY, JSON.stringify(trimmed));
}
function executeCommand(input) {
const trimmed = input.trim();
if (!trimmed) return '';
// Store in history
commandHistory.push(trimmed);
historyIndex = -1;
saveHistory();
const parts = trimmed.split(/\s+/);
const cmd = parts[0].toLowerCase();
const args = parts.slice(1);
if (commands[cmd]) {
if (window.trackEvent) {
window.trackEvent('Terminal Command', { command: cmd, args: args.join(' ') });
}
return commands[cmd](args);
}
return `\n Command not found: ${cmd}. Type 'help' for available commands.\n`;
}
// Typewriter Effect
function typeWriter(element, text, speed) {
return new Promise((resolve) => {
let i = 0;
function tick() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
scrollToBottom();
setTimeout(tick, speed);
} else {
resolve();
}
}
tick();
});
}
function scrollToBottom() {
const output = document.getElementById('terminal-output');
if (output) output.scrollTop = output.scrollHeight;
}
// Output Rendering
function appendOutput(html, className) {
const output = document.getElementById('terminal-output');
const line = document.createElement('div');
line.className = 'terminal-line' + (className ? ' ' + className : '');
line.innerHTML = html;
output.appendChild(line);
scrollToBottom();
}
function appendPromptLine(input) {
appendOutput(
'<span class="terminal-prompt">' + PROMPT + '</span>' +
'<span class="terminal-cmd">' + escapeHtml(input) + '</span>',
'terminal-input-echo'
);
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Initialisation
document.addEventListener('DOMContentLoaded', async function () {
const output = document.getElementById('terminal-output');
const input = document.getElementById('terminal-input');
if (!output || !input) return;
// Welcome sequence
const hasVisited = localStorage.getItem(VISITED_KEY);
if (!hasVisited) {
// First visit: typewriter effect
const bannerEl = document.createElement('pre');
bannerEl.className = 'terminal-line ascii-art';
output.appendChild(bannerEl);
await typeWriter(bannerEl, ASCII_BANNER, 8);
const welcomeEl = document.createElement('div');
welcomeEl.className = 'terminal-line terminal-welcome';
output.appendChild(welcomeEl);
await typeWriter(welcomeEl, WELCOME_MSG, 20);
localStorage.setItem(VISITED_KEY, 'true');
} else {
// Return visit: instant render
const bannerEl = document.createElement('pre');
bannerEl.className = 'terminal-line ascii-art';
bannerEl.textContent = ASCII_BANNER;
output.appendChild(bannerEl);
appendOutput(WELCOME_MSG, 'terminal-welcome');
}
input.focus();
// Click anywhere in terminal to focus input
document.querySelector('.terminal-container').addEventListener('click', () => {
input.focus();
});
// Handle input
input.addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
const val = input.value;
appendPromptLine(val);
const result = executeCommand(val);
if (result === '__CLEAR__') {
output.innerHTML = '';
} else if (result) {
appendOutput(result, 'terminal-result');
}
input.value = '';
scrollToBottom();
}
// Tab auto-completion
if (e.key === 'Tab') {
e.preventDefault();
const val = input.value.trim().toLowerCase();
if (!val) return;
const matches = Object.keys(commands).filter(c => c.startsWith(val));
if (matches.length === 1) {
input.value = matches[0];
} else if (matches.length > 1) {
// Show hints if multiple matches
appendPromptLine(val);
appendOutput(' ' + matches.join(' '), 'terminal-result');
}
}
// Arrow up: previous command
if (e.key === 'ArrowUp') {
e.preventDefault();
if (commandHistory.length === 0) return;
if (historyIndex === -1) {
historyIndex = commandHistory.length - 1;
} else if (historyIndex > 0) {
historyIndex--;
}
input.value = commandHistory[historyIndex] || '';
}
// Arrow down: next command
if (e.key === 'ArrowDown') {
e.preventDefault();
if (historyIndex === -1) return;
if (historyIndex < commandHistory.length - 1) {
historyIndex++;
input.value = commandHistory[historyIndex] || '';
} else {
historyIndex = -1;
input.value = '';
}
}
});
});
// ── Konami Code Detection ─────────────────────────────────────
const konamiCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
let konamiIndex = 0;
document.addEventListener('keydown', (e) => {
if (e.key === konamiCode[konamiIndex]) {
konamiIndex++;
if (konamiIndex === konamiCode.length) {
activateHackerMode();
konamiIndex = 0;
}
} else {
konamiIndex = 0;
}
});
function activateHackerMode() {
const terminal = document.querySelector('.terminal-container');
if (!terminal) return;
terminal.classList.toggle('konami-mode');
if (terminal.classList.contains('konami-mode')) {
appendOutput('\n [SYSTEM] Easter egg activated. Welcome to the Matrix.\n', 'terminal-welcome');
console.log('Matrix mode engaged.');
}
}
})();