Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
714 lines (667 loc) · 22.8 KB
/
Copy pathindex.html
File metadata and controls
714 lines (667 loc) · 22.8 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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MiniOS v2.0 Shell</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Inter:wght@400;600&display=swap" rel="stylesheet" />
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0d1117;
--surface: #161b22;
--border: #30363d;
--green: #3fb950;
--green-dim: #238636;
--cyan: #79c0ff;
--yellow: #e3b341;
--red: #f85149;
--muted: #8b949e;
--text: #c9d1d9;
--prompt: #58a6ff;
}
body {
background: var(--bg);
font-family: 'Inter', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
min-height: 100vh;
padding: 24px 16px 40px;
color: var(--text);
}
/* ── Header ── */
header {
width: 100%;
max-width: 860px;
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 20px;
padding-bottom: 18px;
border-bottom: 1px solid var(--border);
}
.logo {
width: 40px; height: 40px;
background: linear-gradient(135deg, #238636, #3fb950);
border-radius: 10px;
display: flex; align-items: center; justify-content: center;
font-family: 'JetBrains Mono', monospace;
font-weight: 700; font-size: 18px; color: #fff;
flex-shrink: 0;
}
.header-text h1 { font-size: 18px; font-weight: 600; color: var(--text); }
.header-text p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge {
margin-left: auto;
background: var(--green-dim);
color: var(--green);
font-size: 11px; font-weight: 600;
padding: 3px 10px; border-radius: 20px;
letter-spacing: .5px;
}
/* ── Terminal window ── */
.window {
width: 100%; max-width: 860px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.titlebar {
display: flex; align-items: center; gap: 8px;
background: #1c2128;
padding: 12px 16px;
border-bottom: 1px solid var(--border);
user-select: none;
}
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.red { background: #ff5f57; }
.dot.yellow { background: #febc2e; }
.dot.green { background: #28c840; }
.titlebar-label {
margin-left: auto; margin-right: auto;
font-family: 'JetBrains Mono', monospace;
font-size: 12px; color: var(--muted);
}
/* ── Output area ── */
#output {
font-family: 'JetBrains Mono', monospace;
font-size: 13.5px;
line-height: 1.7;
padding: 20px 24px 8px;
min-height: 340px;
max-height: 520px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-word;
scrollbar-width: thin;
scrollbar-color: var(--border) transparent;
}
#output::-webkit-scrollbar { width: 6px; }
#output::-webkit-scrollbar-track { background: transparent; }
#output::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
/* ── Line types ── */
.line-prompt { color: var(--prompt); }
.line-cmd { color: var(--text); }
.line-output { color: var(--green); }
.line-error { color: var(--red); }
.line-info { color: var(--cyan); }
.line-muted { color: var(--muted); }
.line-yellow { color: var(--yellow); }
/* ── Input row ── */
.input-row {
display: flex; align-items: center; gap: 10px;
padding: 12px 24px 16px;
border-top: 1px solid var(--border);
background: #161b22;
}
.ps1 {
font-family: 'JetBrains Mono', monospace;
font-size: 13.5px;
color: var(--prompt);
white-space: nowrap;
flex-shrink: 0;
}
#cmd-input {
flex: 1;
background: transparent;
border: none; outline: none;
font-family: 'JetBrains Mono', monospace;
font-size: 13.5px;
color: var(--text);
caret-color: var(--green);
}
#cmd-input::placeholder { color: var(--muted); }
/* ── Helper chips ── */
.chips {
width: 100%; max-width: 860px;
display: flex; flex-wrap: wrap; gap: 8px;
margin-top: 14px;
}
.chip {
background: #1c2128;
border: 1px solid var(--border);
color: var(--muted);
font-family: 'JetBrains Mono', monospace;
font-size: 11.5px;
padding: 5px 12px; border-radius: 6px;
cursor: pointer;
transition: border-color .15s, color .15s;
user-select: none;
}
.chip:hover { border-color: var(--prompt); color: var(--prompt); }
/* ── Fade-in animation ── */
@keyframes fadeIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }
.new-line { animation: fadeIn .12s ease-out; }
</style>
</head>
<body>
<header>
<div class="logo">$</div>
<div class="header-text">
<h1>MiniOS v2.0 Shell</h1>
<p>Shell · virtual files · memory · scheduler · structured feedback</p>
</div>
<span class="badge">V2.0</span>
</header>
<div class="window">
<div class="titlebar">
<span class="dot red"></span>
<span class="dot yellow"></span>
<span class="dot green"></span>
<span class="titlebar-label">miniOS:/home</span>
</div>
<div id="output"></div>
<div class="input-row">
<span class="ps1">miniOS:/home$ </span>
<input id="cmd-input" type="text" autocomplete="off" spellcheck="false" autofocus placeholder="type a command…" />
</div>
</div>
<div class="chips">
<span class="chip" onclick="runChip('help')">help</span>
<span class="chip" onclick="runChip('echo Hello World')">echo Hello World</span>
<span class="chip" onclick="runChip('math 10 + 5')">math 10 + 5</span>
<span class="chip" onclick="runChip('math 6 * 7')">math 6 * 7</span>
<span class="chip" onclick="runChip('math 20 / 4')">math 20 / 4</span>
<span class="chip" onclick="runChip('math 10 - 3')">math 10 - 3</span>
<span class="chip" onclick="runChip('touch demo.txt')">touch demo.txt</span>
<span class="chip" onclick="runChip('write demo.txt hello world')">write demo.txt hello world</span>
<span class="chip" onclick="runChip('read demo.txt')">read demo.txt</span>
<span class="chip" onclick="runChip('ls')">ls</span>
<span class="chip" onclick="runChip('mem')">mem</span>
<span class="chip" onclick="runChip('run')">run</span>
<span class="chip" onclick="runChip('add 5')">add 5</span>
<span class="chip" onclick="runChip('ecoh Hello World')">ecoh Hello World</span>
<span class="chip" onclick="runChip('clear')">clear</span>
<span class="chip" onclick="runChip('exit')">exit</span>
</div>
<script>
/* ── History ── */
const history = [];
let histIdx = -1;
const RAM_SIZE = 1024 * 1024;
const BLOCK_HEADER_SIZE = 16;
const scheduler = { counter: 0, activeTasks: 1 };
const files = [];
/* ── Output helpers ── */
const out = document.getElementById('output');
function addLine(text, cls = 'line-output') {
const div = document.createElement('div');
div.className = cls + ' new-line';
div.textContent = text;
out.appendChild(div);
out.scrollTop = out.scrollHeight;
}
function addBlank() { addLine('', 'line-muted'); }
/* ── String utility (mirrors string.c) ── */
function myStrToInt(s) { return parseInt(s, 10) || 0; }
function myClamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function myIntToStr(value) {
return String(value);
}
function align8(n) {
return (n + 7) & ~7;
}
function totalUsedMemory() {
return files.reduce((sum, file) => sum + align8(file.data.length + 1), 0);
}
function totalRawMemory() {
return files.reduce((sum, file) => sum + align8(file.data.length + 1) + BLOCK_HEADER_SIZE, 0);
}
function findFile(name) {
return files.find((file) => file.name === name) || null;
}
function isValidFileName(name) {
return !!name && name.length > 0 && name.length < 32;
}
function printSeparator(count = 32) {
addLine('-'.repeat(count), 'line-muted');
}
function printTitle(title) {
addBlank();
addLine(`## ${title}`, 'line-info');
printSeparator(32);
}
function printKv(key, value, padTo = 6, cls = 'line-output') {
addLine(`${key.padEnd(Math.max(key.length, padTo), ' ')}: ${value}`, cls);
}
function printOk(msg) {
addLine(`[OK] ${msg}`, 'line-output');
}
function printError(msg) {
addLine(`[ERROR] ${msg}`, 'line-error');
}
function printHint(msg) {
addLine(msg, 'line-yellow');
}
function levenshtein(a, b) {
const dp = Array.from({ length: a.length + 1 }, () => Array(b.length + 1).fill(0));
for (let i = 0; i <= a.length; i++) dp[i][0] = i;
for (let j = 0; j <= b.length; j++) dp[0][j] = j;
for (let i = 1; i <= a.length; i++) {
for (let j = 1; j <= b.length; j++) {
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
dp[i][j] = Math.min(
dp[i - 1][j] + 1,
dp[i][j - 1] + 1,
dp[i - 1][j - 1] + cost
);
}
}
return dp[a.length][b.length];
}
function suggestCommand(cmd) {
const commands = ['help', 'echo', 'math', 'add', 'touch', 'write', 'read', 'ls', 'delete', 'mem', 'run', 'clear', 'exit', 'quit'];
let best = null;
let bestScore = Infinity;
for (const candidate of commands) {
const score = levenshtein(cmd, candidate);
if (score < bestScore) {
best = candidate;
bestScore = score;
}
}
return bestScore <= 2 ? best : null;
}
function isIntegerToken(value) {
return /^-?\d+$/.test(value || '');
}
function explainExpectedUsage(cmd) {
const messages = {
help: "This command does not need any extra input. Example: 'help'",
echo: "This command prints text. Example: 'echo Hello World'",
math: "This command needs two numbers and one operator. Example: 'math 8 + 2'",
add: "This command needs two numbers. Example: 'add 5 10'",
touch: "This command needs a filename. Example: 'touch notes.txt'",
write: "This command needs a filename and some text. Example: 'write notes.txt hello world'",
read: "This command needs a filename. Example: 'read notes.txt'",
delete: "This command needs a filename. Example: 'delete notes.txt'",
ls: "This command lists all virtual files. Example: 'ls'",
mem: "This command shows memory usage. Example: 'mem'",
run: "This command runs one scheduler tick. Example: 'run'",
clear: "This command clears the screen. Example: 'clear'",
exit: "This command closes MiniOS. Example: 'exit'",
quit: "This command closes MiniOS. Example: 'quit'"
};
return messages[cmd] || "Type 'help' to see the available commands.";
}
function handleExtraArgs(cmd, args) {
if (args.length > 0) {
printError(`The '${cmd}' command does not take extra arguments.`);
printHint(explainExpectedUsage(cmd));
return true;
}
return false;
}
function findClosestOperator(op) {
const operators = ['+', '-', '*', '/'];
let best = null;
let bestScore = Infinity;
for (const candidate of operators) {
const score = levenshtein(op, candidate);
if (score < bestScore) {
best = candidate;
bestScore = score;
}
}
return bestScore <= 1 ? best : null;
}
/* ── Math module (mirrors math.c) ── */
function myMultiply(a, b) {
let result = 0, neg = false;
if (b < 0) { b = -b; neg = !neg; }
if (a < 0) { a = -a; neg = !neg; }
for (let i = 0; i < b; i++) result += a;
return neg ? -result : result;
}
function myDivide(a, b) {
if (b === 0) return null;
let neg = false;
if (a < 0) { a = -a; neg = !neg; }
if (b < 0) { b = -b; neg = !neg; }
let result = 0;
while (a >= b) { a -= b; result++; }
return neg ? -result : result;
}
/* ── Parser (mirrors parser.c) ── */
function parseCommand(input) {
const trimmed = input.trim();
if (!trimmed) return null;
const tokens = trimmed.split(/\s+/);
return { cmd: tokens[0].toLowerCase(), args: tokens.slice(1), argc: tokens.length - 1 };
}
/* ── Command handlers ── */
function handleHelp() {
printTitle('MiniOS v2.0 - Commands');
addLine('help Show this menu', 'line-output');
addLine('echo <text...> Print text', 'line-output');
addLine('math <a> <op> <b> Arithmetic: op is + - * /', 'line-output');
addLine('add <a> <b> Quick addition helper', 'line-output');
addLine('touch <file> Create file (if missing)', 'line-output');
addLine('write <file> <data> Write data to file (overwrites)', 'line-output');
addLine('read <file> Read file contents', 'line-output');
addLine('ls List files', 'line-output');
addLine('delete <file> Delete file', 'line-output');
addLine('mem Show memory status', 'line-output');
addLine('run Run one scheduler tick (demo)', 'line-output');
addLine('clear Clear screen + show boot banner', 'line-output');
addLine('exit Quit MiniOS', 'line-output');
printSeparator(32);
}
function handleEcho(args) {
if (args.length === 0) {
printError("The 'echo' command needs some text to print.");
printHint(explainExpectedUsage('echo'));
return;
}
addLine(args.join(' '), 'line-output');
}
function handleMath(args) {
if (args.length < 3) {
printError("The 'math' command requires two numbers and an operator.");
printHint(explainExpectedUsage('math'));
return;
}
if (!isIntegerToken(args[0]) || !isIntegerToken(args[2])) {
printError("The 'math' command expects numbers on both sides of the operator.");
printHint(explainExpectedUsage('math'));
return;
}
const a = myStrToInt(args[0]);
const op = args[1];
const b = myStrToInt(args[2]);
let r;
if (op === '+') r = a + b;
else if (op === '-') r = a - b;
else if (op === '*') r = myMultiply(a, b);
else if (op === '/') {
r = myDivide(a, b);
if (r === null) { printError('division by zero'); return; }
}
else {
printError(`Unknown operator: '${op}'`);
const maybeOp = findClosestOperator(op);
if (maybeOp) printHint(`Did you mean '${maybeOp}'? Example: 'math ${a} ${maybeOp} ${b}'`);
else printHint("Use one of these operators: +, -, *, /");
return;
}
printTitle('Math Result');
printKv('A', a, 6);
printKv('Op', op, 6);
printKv('B', b, 6);
printSeparator(16);
printKv('Result', r, 6, 'line-yellow');
}
function handleAdd(args) {
if (args.length < 2) {
printError("The 'add' command requires numbers. Example: 'add 5 10'");
return;
}
if (!isIntegerToken(args[0]) || !isIntegerToken(args[1])) {
printError("The 'add' command only works with numbers.");
printHint(explainExpectedUsage('add'));
return;
}
const a = myStrToInt(args[0]);
const b = myStrToInt(args[1]);
printTitle('Math Result');
printKv('A', a, 6);
printKv('Op', '+', 6);
printKv('B', b, 6);
printSeparator(16);
printKv('Result', a + b, 6, 'line-yellow');
}
function handleTouch(args) {
if (args.length < 1) {
printError("The 'touch' command needs a filename.");
printHint(explainExpectedUsage('touch'));
return;
}
const name = args[0];
if (!isValidFileName(name)) {
printError('cannot create file');
printHint("Use a short file name under 32 characters. Example: 'touch notes.txt'");
return;
}
if (args.length > 1) {
printError("The 'touch' command creates one file at a time.");
printHint(explainExpectedUsage('touch'));
return;
}
if (!findFile(name)) {
if (files.length >= 64) {
printError('cannot create file');
return;
}
files.push({ name, data: '' });
}
printOk(`File '${name}' created`);
}
function handleWrite(args) {
if (args.length < 2) {
printError("The 'write' command needs a filename and some text.");
printHint(explainExpectedUsage('write'));
return;
}
const name = args[0];
const data = args.slice(1).join(' ');
if (!isValidFileName(name)) {
printError('write failed (out of RAM / invalid name)');
printHint("Try a valid file name like 'write notes.txt hello'");
return;
}
const existing = findFile(name);
const currentRaw = totalRawMemory() - (existing ? align8(existing.data.length + 1) + BLOCK_HEADER_SIZE : 0);
const neededRaw = align8(data.length + 1) + BLOCK_HEADER_SIZE;
if (!existing && files.length >= 64) {
printError('write failed (out of RAM / invalid name)');
printHint('The virtual file table is full. Delete a file and try again.');
return;
}
if (currentRaw + neededRaw > RAM_SIZE) {
printError('write failed (out of RAM / invalid name)');
printHint('The virtual RAM is full. Delete some files or write smaller content.');
return;
}
if (existing) existing.data = data;
else files.push({ name, data });
printOk(`Data written to '${name}'`);
}
function handleRead(args) {
if (args.length < 1) {
printError("The 'read' command needs a filename.");
printHint(explainExpectedUsage('read'));
return;
}
if (args.length > 1) {
printError("The 'read' command accepts only one filename.");
printHint(explainExpectedUsage('read'));
return;
}
const file = findFile(args[0]);
if (!file) {
printError('File not found');
printHint(`Create it first with 'touch ${args[0]}' or check the file name with 'ls'.`);
return;
}
addLine(`----- FILE: ${file.name} -----`, 'line-info');
addLine(file.data, 'line-output');
printSeparator(24);
}
function handleDelete(args) {
if (args.length < 1) {
printError("The 'delete' command needs a filename.");
printHint(explainExpectedUsage('delete'));
return;
}
if (args.length > 1) {
printError("The 'delete' command removes one file at a time.");
printHint(explainExpectedUsage('delete'));
return;
}
const idx = files.findIndex((file) => file.name === args[0]);
if (idx < 0) {
printError('file not found');
printHint("Use 'ls' to check available files before deleting.");
return;
}
const [removed] = files.splice(idx, 1);
printOk(`File '${removed.name}' deleted`);
}
function handleLs() {
printTitle('Files in Virtual System');
if (files.length === 0) {
addLine('(empty)', 'line-muted');
printSeparator(32);
return;
}
files.forEach((file, idx) => {
const pad = myClamp(12 - file.name.length, 1, 12);
addLine(`[${myIntToStr(idx + 1)}] ${file.name}${' '.repeat(pad)}(${file.data.length} bytes)`, 'line-output');
});
printSeparator(32);
}
function handleMem() {
printTitle('Memory Status');
printKv('Total', '1 MB', 6);
printKv('Used', totalUsedMemory(), 6);
printKv('Free', RAM_SIZE - totalUsedMemory(), 6);
printSeparator(32);
}
function handleRun() {
scheduler.counter += scheduler.activeTasks;
printOk('Scheduler tick executed');
printKv('Tasks ran', scheduler.activeTasks, 10);
printKv('Counter', scheduler.counter, 10);
}
function handleClear() {
out.innerHTML = '';
boot();
}
function handleUnknown(cmd) {
addLine(`Unknown command: '${cmd}'`, 'line-error');
const suggestion = suggestCommand(cmd);
if (suggestion) {
addLine(`Did you mean '${suggestion}'?`, 'line-yellow');
addLine(explainExpectedUsage(suggestion), 'line-muted');
} else {
addLine("Type 'help' to see the available commands.", 'line-muted');
}
}
/* ── Main executor ── */
function execLine(raw) {
const trimmed = raw.trim();
if (!trimmed) return true;
/* echo the prompt + command */
addLine('miniOS:/home$ ' + raw, 'line-prompt');
const parsed = parseCommand(raw);
if (!parsed) return true;
switch (parsed.cmd) {
case 'help':
if (handleExtraArgs('help', parsed.args)) break;
handleHelp();
break;
case 'echo': handleEcho(parsed.args); break;
case 'math': handleMath(parsed.args); break;
case 'add': handleAdd(parsed.args); break;
case 'touch': handleTouch(parsed.args); break;
case 'write': handleWrite(parsed.args); break;
case 'read': handleRead(parsed.args); break;
case 'ls':
if (handleExtraArgs('ls', parsed.args)) break;
handleLs();
break;
case 'delete': handleDelete(parsed.args); break;
case 'mem':
if (handleExtraArgs('mem', parsed.args)) break;
handleMem();
break;
case 'run':
if (handleExtraArgs('run', parsed.args)) break;
handleRun();
break;
case 'clear': handleClear(); return true;
case 'exit':
case 'quit':
if (parsed.args.length > 0) {
printError(`The '${parsed.cmd}' command does not take extra arguments.`);
printHint(explainExpectedUsage(parsed.cmd));
addBlank();
return true;
}
printOk('Goodbye!');
addBlank();
document.getElementById('cmd-input').disabled = true;
return false;
default:
handleUnknown(parsed.cmd);
}
addBlank();
return true;
}
/* ── Boot banner ── */
function boot() {
addBlank();
addLine('## MiniOS v2.0 Loaded', 'line-info');
printSeparator(32);
addLine("Type 'help' to begin", 'line-muted');
addBlank();
}
/* ── Chip helper ── */
function runChip(cmd) {
const input = document.getElementById('cmd-input');
input.value = cmd;
input.focus();
submit();
}
/* ── Input handling ── */
function submit() {
const input = document.getElementById('cmd-input');
const val = input.value;
if (!val.trim()) return;
history.unshift(val);
histIdx = -1;
input.value = '';
execLine(val);
}
document.getElementById('cmd-input').addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
submit();
} else if (e.key === 'ArrowUp') {
e.preventDefault();
if (histIdx < history.length - 1) { histIdx++; this.value = history[histIdx]; }
} else if (e.key === 'ArrowDown') {
e.preventDefault();
if (histIdx > 0) { histIdx--; this.value = history[histIdx]; }
else { histIdx = -1; this.value = ''; }
}
});
boot();
</script>
</body>
</html>