Repository navigation
Expand file tree
/
Copy pathcli.cpp
More file actions
763 lines (679 loc) · 24.2 KB
/
Copy pathcli.cpp
File metadata and controls
763 lines (679 loc) · 24.2 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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
extern "C" {
uint8_t get_keyboard_input_nonblock();
char shell_scancode_to_ascii(uint8_t scancode, bool shift);
int get_shell_file_count();
void get_shell_file_name(int index, char *out);
uint32_t get_shell_file_size(int index);
bool get_shell_file_is_dir(int index);
void shell_refresh_files();
bool shell_is_fs_mounted();
bool shell_read_file(const char *filename, char *buffer, uint32_t max_size);
bool shell_write_file(const char *filename, const char *data, uint32_t size);
bool shell_delete_file(const char *filename);
bool shell_mkdir(const char *name);
bool shell_rmdir(const char *name);
bool shell_move_file(const char *src, const char *dest);
bool shell_change_dir(const char *path);
const char *shell_get_current_path();
void put_pixel(int x, int y, uint32_t color);
void delay(uint32_t count);
}
struct Graphics {
uint32_t *framebuffer;
uint32_t width;
uint32_t height;
uint32_t pitch;
bool active;
};
extern Graphics screen;
// ============================================================================
// 8x8 BITMAP FONT FOR Oyster (CHARACTER MAP INITIALIZER)
// ============================================================================
static uint8_t Oyster_font[128][8] = {0};
static void Oyster_init_font() {
static bool font_inited = false;
if (font_inited)
return;
font_inited = true;
struct CharDef {
char c;
uint8_t data[8];
};
CharDef chars[] = {
{'A', {0x18, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00}},
{'B', {0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00}},
{'C', {0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C, 0x00}},
{'D', {0x78, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0x78, 0x00}},
{'E', {0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00}},
{'F', {0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x00}},
{'G', {0x3C, 0x66, 0x60, 0x6E, 0x66, 0x66, 0x3C, 0x00}},
{'H', {0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00}},
{'I', {0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00}},
{'J', {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x6C, 0x38, 0x00}},
{'K', {0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00}},
{'L', {0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00}},
{'M', {0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63, 0x00}},
{'N', {0x66, 0x76, 0x7E, 0x7E, 0x6E, 0x66, 0x66, 0x00}},
{'O', {0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}},
{'P', {0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00}},
{'Q', {0x3C, 0x66, 0x66, 0x66, 0x6A, 0x3C, 0x06, 0x00}},
{'R', {0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66, 0x00}},
{'S', {0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C, 0x00}},
{'T', {0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}},
{'U', {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}},
{'V', {0x66, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x00}},
{'W', {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}},
{'X', {0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00}},
{'Y', {0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x00}},
{'Z', {0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E, 0x00}},
{'a', {0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E, 0x00}},
{'b', {0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x00}},
{'c', {0x00, 0x00, 0x3C, 0x60, 0x60, 0x66, 0x3C, 0x00}},
{'d', {0x06, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x3E, 0x00}},
{'e', {0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00}},
{'f', {0x1C, 0x30, 0x7C, 0x30, 0x30, 0x30, 0x30, 0x00}},
{'g', {0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C}},
{'h', {0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x00}},
{'i', {0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}},
{'j', {0x06, 0x00, 0x06, 0x06, 0x06, 0x66, 0x3C, 0x00}},
{'k', {0x60, 0x60, 0x6C, 0x78, 0x78, 0x6C, 0x66, 0x00}},
{'l', {0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x1C, 0x00}},
{'m', {0x00, 0x00, 0x76, 0x7F, 0x6B, 0x6B, 0x6B, 0x00}},
{'n', {0x00, 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x00}},
{'o', {0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00}},
{'p', {0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60}},
{'q', {0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x06}},
{'r', {0x00, 0x00, 0x3E, 0x60, 0x60, 0x60, 0x60, 0x00}},
{'s', {0x00, 0x00, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0x00}},
{'t', {0x30, 0x30, 0x7C, 0x30, 0x30, 0x30, 0x1C, 0x00}},
{'u', {0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E, 0x00}},
{'v', {0x00, 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00}},
{'w', {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x3E, 0x36, 0x00}},
{'x', {0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00}},
{'y', {0x00, 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x3C}},
{'z', {0x00, 0x00, 0x7E, 0x0C, 0x18, 0x30, 0x7E, 0x00}},
{'0', {0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C, 0x00}},
{'1', {0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00}},
{'2', {0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E, 0x00}},
{'3', {0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00}},
{'4', {0x06, 0x0E, 0x1E, 0x36, 0x7F, 0x06, 0x06, 0x00}},
{'5', {0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0x00}},
{'6', {0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00}},
{'7', {0x7E, 0x66, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x00}},
{'8', {0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00}},
{'9', {0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C, 0x00}},
{'.', {0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00}},
{':', {0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00}},
{' ', {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{'-', {0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00}},
{'(', {0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00}},
{')', {0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00}},
{'@', {0x3C, 0x66, 0x6E, 0x6E, 0x60, 0x66, 0x3C, 0x00}},
{',', {0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30}},
{'+', {0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00}},
{'/', {0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00, 0x00}},
{'_', {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00}},
{'>', {0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00}},
{'<', {0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00}},
{'|', {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}},
{'*', {0x00, 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00}},
{'=', {0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00}},
{'!', {0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00}},
{'"', {0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00}},
{'#', {0x66, 0x66, 0x7E, 0x66, 0x7E, 0x66, 0x66, 0x00}},
{'$', {0x18, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0x18, 0x00}},
{'%', {0x62, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x46, 0x00}},
{'&', {0x3C, 0x66, 0x3C, 0x38, 0x6E, 0x66, 0x3B, 0x00}},
{'\'', {0x06, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}},
{';', {0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30, 0x00}},
{'?', {0x3C, 0x66, 0x06, 0x0C, 0x18, 0x00, 0x18, 0x00}},
{'[', {0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x00}},
{'\\', {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x00, 0x00}},
{']', {0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x00}},
{'^', {0x18, 0x3C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00}},
{'`', {0x18, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}},
{'{', {0x0E, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0E, 0x00}},
{'}', {0x70, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x70, 0x00}},
{'~', {0x3B, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}};
for (unsigned i = 0; i < sizeof(chars) / sizeof(chars[0]); i++) {
uint8_t code = (uint8_t)chars[i].c;
if (code < 128) {
for (int j = 0; j < 8; j++) {
Oyster_font[code][j] = chars[i].data[j];
}
}
}
}
// ============================================================================
// Oyster SCREEN OUTPUT ENGINE
// ============================================================================
#define Oyster_BG_COLOR 0x0A0F1D
#define Oyster_FG_COLOR 0x00FF66
static int Oyster_cursor_x = 0; // column (0 .. Oyster_COLS - 1)
static int Oyster_cursor_y = 0; // row (0 .. Oyster_ROWS - 1)
static int Oyster_COLS = 100;
static int Oyster_ROWS = 75;
static void Oyster_draw_glyph(int col, int row, char c, uint32_t fg, uint32_t bg) {
if (!screen.active || !screen.framebuffer)
return;
Oyster_init_font();
int start_x = col * 8;
int start_y = row * 8;
uint8_t glyph_idx = (uint8_t)c;
if (glyph_idx > 127)
glyph_idx = '?';
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
int px = start_x + j;
int py = start_y + i;
if (px >= (int)screen.width || py >= (int)screen.height)
continue;
bool pixel_set = (Oyster_font[glyph_idx][i] & (1 << (7 - j))) != 0;
screen.framebuffer[py * (screen.pitch / 4) + px] = pixel_set ? fg : bg;
}
}
}
static void Oyster_scroll_up() {
if (!screen.active || !screen.framebuffer)
return;
uint32_t pitch_dwords = screen.pitch / 4;
uint32_t line_height = 8;
uint32_t total_scroll_pixels = (screen.height - line_height) * pitch_dwords;
// Shift screen buffer up by 8 pixel lines
for (uint32_t i = 0; i < total_scroll_pixels; i++) {
screen.framebuffer[i] = screen.framebuffer[i + (line_height * pitch_dwords)];
}
// Clear bottom 8 pixel lines
uint32_t bottom_start = total_scroll_pixels;
uint32_t total_pixels = screen.width * screen.height;
for (uint32_t i = bottom_start; i < total_pixels; i++) {
screen.framebuffer[i] = Oyster_BG_COLOR;
}
}
extern "C" void Oyster_clear() {
if (!screen.active || !screen.framebuffer)
return;
uint32_t total_pixels = screen.width * screen.height;
for (uint32_t i = 0; i < total_pixels; i++) {
screen.framebuffer[i] = Oyster_BG_COLOR;
}
Oyster_cursor_x = 0;
Oyster_cursor_y = 0;
Oyster_COLS = screen.width / 8;
Oyster_ROWS = screen.height / 8;
}
extern "C" void Oyster_putchar(char c) {
if (c == '\n') {
Oyster_cursor_x = 0;
Oyster_cursor_y++;
} else if (c == '\r') {
Oyster_cursor_x = 0;
} else if (c == '\b') {
if (Oyster_cursor_x > 0) {
Oyster_cursor_x--;
Oyster_draw_glyph(Oyster_cursor_x, Oyster_cursor_y, ' ', Oyster_FG_COLOR, Oyster_BG_COLOR);
}
} else if (c == '\t') {
int spaces = 4 - (Oyster_cursor_x % 4);
for (int i = 0; i < spaces; i++) {
Oyster_putchar(' ');
}
} else {
Oyster_draw_glyph(Oyster_cursor_x, Oyster_cursor_y, c, Oyster_FG_COLOR, Oyster_BG_COLOR);
Oyster_cursor_x++;
if (Oyster_cursor_x >= Oyster_COLS) {
Oyster_cursor_x = 0;
Oyster_cursor_y++;
}
}
while (Oyster_cursor_y >= Oyster_ROWS) {
Oyster_scroll_up();
Oyster_cursor_y = Oyster_ROWS - 1;
}
}
extern "C" void Oyster_print(const char *str) {
while (*str) {
Oyster_putchar(*str++);
}
}
extern "C" void Oyster_println(const char *str) {
Oyster_print(str);
Oyster_putchar('\n');
}
// Simple integer formatting helper for Oyster_printf
static void Oyster_print_num(int val, int base) {
char buf[32];
if (val == 0) {
Oyster_putchar('0');
return;
}
bool neg = false;
if (val < 0 && base == 10) {
neg = true;
val = -val;
}
int pos = 0;
const char *digits = "0123456789ABCDEF";
while (val > 0) {
buf[pos++] = digits[val % base];
val /= base;
}
if (neg) buf[pos++] = '-';
while (pos > 0) {
Oyster_putchar(buf[--pos]);
}
}
extern "C" void Oyster_printf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
while (*fmt) {
if (*fmt == '%') {
fmt++;
if (*fmt == 's') {
const char *s = va_arg(args, const char *);
Oyster_print(s ? s : "(null)");
} else if (*fmt == 'd' || *fmt == 'i') {
int d = va_arg(args, int);
Oyster_print_num(d, 10);
} else if (*fmt == 'u') {
unsigned int u = va_arg(args, unsigned int);
Oyster_print_num(u, 10);
} else if (*fmt == 'x' || *fmt == 'X') {
int x = va_arg(args, int);
Oyster_print_num(x, 16);
} else if (*fmt == 'c') {
char c = (char)va_arg(args, int);
Oyster_putchar(c);
} else if (*fmt == '%') {
Oyster_putchar('%');
}
} else {
Oyster_putchar(*fmt);
}
fmt++;
}
va_end(args);
}
// ============================================================================
// HELPER UTILITIES FOR STRING MANIPULATION
// ============================================================================
static int Oyster_strlen(const char *s) {
int len = 0;
while (s[len]) len++;
return len;
}
static bool Oyster_strcmp(const char *s1, const char *s2) {
while (*s1 && *s2) {
if (*s1 != *s2) return false;
s1++;
s2++;
}
return *s1 == *s2;
}
static const char *Oyster_strstr(const char *haystack, const char *needle) {
if (!*needle) return haystack;
for (; *haystack; haystack++) {
const char *h = haystack;
const char *n = needle;
while (*h && *n && *h == *n) {
h++;
n++;
}
if (!*n) return haystack;
}
return NULL;
}
// ============================================================================
// COMMAND REGISTRATION SYSTEM
// ============================================================================
typedef void (*Oyster_cmd_func_t)(int argc, char **argv);
struct OysterCommand {
char name[32];
char description[64];
Oyster_cmd_func_t func;
};
#define MAX_Oyster_COMMANDS 64
static OysterCommand Oyster_commands[MAX_Oyster_COMMANDS];
static int Oyster_command_count = 0;
extern "C" bool Oyster_register_command(const char *name, const char *description,
Oyster_cmd_func_t func) {
if (Oyster_command_count >= MAX_Oyster_COMMANDS)
return false;
int i = 0;
while (name[i] && i < 31) {
Oyster_commands[Oyster_command_count].name[i] = name[i];
i++;
}
Oyster_commands[Oyster_command_count].name[i] = '\0';
i = 0;
while (description[i] && i < 63) {
Oyster_commands[Oyster_command_count].description[i] = description[i];
i++;
}
Oyster_commands[Oyster_command_count].description[i] = '\0';
Oyster_commands[Oyster_command_count].func = func;
Oyster_command_count++;
return true;
}
// ============================================================================
// BUILT-IN UNIX & SYSTEM COMMANDS
// ============================================================================
static bool Oyster_running = true;
static void cmd_help(int argc, char **argv) {
Oyster_println("Available Commands:");
Oyster_println("------------------------------------------------------------");
for (int i = 0; i < Oyster_command_count; i++) {
Oyster_printf(" %-10s : %s\n", Oyster_commands[i].name,
Oyster_commands[i].description);
}
Oyster_println("------------------------------------------------------------");
Oyster_println("Press F12 to switch back to MNDE (Milla Next Desktop environment).");
}
static void cmd_clear(int argc, char **argv) {
Oyster_clear();
}
static void cmd_echo(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
Oyster_print(argv[i]);
if (i < argc - 1)
Oyster_print(" ");
}
Oyster_println("");
}
static void cmd_exit(int argc, char **argv) {
Oyster_running = false;
}
static void cmd_ls(int argc, char **argv) {
shell_refresh_files();
if (!shell_is_fs_mounted()) {
Oyster_println("ls: No mounted filesystem found.");
return;
}
int count = get_shell_file_count();
if (count == 0) {
Oyster_println("ls: Directory is empty.");
return;
}
Oyster_printf("Directory Listing (%d files):\n", count);
for (int i = 0; i < count; i++) {
char fname[64];
get_shell_file_name(i, fname);
uint32_t fsize = get_shell_file_size(i);
bool is_dir = get_shell_file_is_dir(i);
if (is_dir) {
Oyster_printf(" [DIR] %-24s\n", fname);
} else {
Oyster_printf(" [FILE] %-24s %u bytes\n", fname, fsize);
}
}
}
static void cmd_cat(int argc, char **argv) {
if (argc < 2) {
Oyster_println("Usage: cat <filename>");
return;
}
static char cat_buf[32768];
if (shell_read_file(argv[1], cat_buf, sizeof(cat_buf) - 1)) {
Oyster_println(cat_buf);
} else {
Oyster_printf("cat: %s: No such file or unable to read\n", argv[1]);
}
}
static void cmd_grep(int argc, char **argv) {
if (argc < 3) {
Oyster_println("Usage: grep <pattern> <filename>");
return;
}
const char *pattern = argv[1];
const char *filename = argv[2];
static char grep_buf[32768];
if (!shell_read_file(filename, grep_buf, sizeof(grep_buf) - 1)) {
Oyster_printf("grep: %s: No such file or unable to read\n", filename);
return;
}
char *line = grep_buf;
while (*line) {
char *end = line;
while (*end && *end != '\n' && *end != '\r') {
end++;
}
char saved = *end;
*end = '\0';
if (Oyster_strstr(line, pattern)) {
Oyster_println(line);
}
if (saved == '\0')
break;
line = end + 1;
if (saved == '\r' && *line == '\n')
line++;
}
}
static void cmd_rm(int argc, char **argv) {
if (argc < 2) {
Oyster_println("Usage: rm [-f] <filename> [filename2 ...]");
return;
}
for (int i = 1; i < argc; i++) {
if (Oyster_strcmp(argv[i], "-f") || Oyster_strcmp(argv[i], "-rf") ||
Oyster_strcmp(argv[i], "-r")) {
continue;
}
if (shell_delete_file(argv[i])) {
Oyster_printf("rm: File '%s' deleted successfully.\n", argv[i]);
} else {
Oyster_printf("rm: cannot remove '%s': No such file or operation failed\n",
argv[i]);
}
}
}
static void cmd_mname(int argc, char **argv) {
Oyster_clear();
Oyster_println(" ");
Oyster_println("Kernel: 2.1");
Oyster_println("MPra-RE 2.0.1");
Oyster_println("Milla-Next-Desktop-Enviroment: 1.1.3");
Oyster_println("Oyster Command Line: 1.0");
Oyster_println("Dev. Date: 17.09.2026");
Oyster_println(" ");
Oyster_println("===================================================");
Oyster_println(" Milla OS ");
Oyster_println(" Version 2.1.4");
Oyster_println(" Codename: Appril");
Oyster_println("===================================================");
Oyster_println(" ");
Oyster_println(" MillaOS is still in development ");
Oyster_println("If you have problems or questions fell free to send an email to:");
Oyster_println("millaos@floridevs.dedyn.io");
Oyster_println(" ");
}
static void cmd_mkdir(int argc, char **argv) {
if (argc < 2) {
Oyster_println("Usage: mkdir <dirname>");
return;
}
if (!shell_is_fs_mounted()) {
Oyster_println("mkdir: No filesystem mounted.");
return;
}
if (shell_mkdir(argv[1])) {
Oyster_printf("mkdir: Directory '%s' created.\n", argv[1]);
shell_refresh_files();
} else {
Oyster_printf("mkdir: Failed to create '%s'.\n", argv[1]);
}
}
static void cmd_rmdir(int argc, char **argv) {
if (argc < 2) {
Oyster_println("Usage: rmdir <dirname>");
return;
}
if (!shell_is_fs_mounted()) {
Oyster_println("rmdir: No filesystem mounted.");
return;
}
if (shell_rmdir(argv[1])) {
Oyster_printf("rmdir: Directory '%s' removed.\n", argv[1]);
shell_refresh_files();
} else {
Oyster_printf("rmdir: Failed to remove '%s' (not empty or not found).\n", argv[1]);
}
}
static void cmd_mv(int argc, char **argv) {
if (argc < 3) {
Oyster_println("Usage: mv <source> <destination>");
return;
}
if (!shell_is_fs_mounted()) {
Oyster_println("mv: No filesystem mounted.");
return;
}
if (shell_move_file(argv[1], argv[2])) {
Oyster_printf("mv: '%s' -> '%s' OK.\n", argv[1], argv[2]);
shell_refresh_files();
} else {
Oyster_printf("mv: Failed to move '%s'.\n", argv[1]);
}
}
static void cmd_cd(int argc, char **argv) {
if (argc < 2) {
Oyster_println("Usage: cd <path>");
return;
}
if (!shell_is_fs_mounted()) {
Oyster_println("cd: No filesystem mounted.");
return;
}
if (shell_change_dir(argv[1])) {
shell_refresh_files();
} else {
Oyster_printf("cd: '%s': No such directory.\n", argv[1]);
}
}
static void cmd_pwd(int argc, char **argv) {
Oyster_println(shell_get_current_path());
}
static void Oyster_init_commands() { //set commands
if (Oyster_command_count > 0)
return;
Oyster_register_command("help", "List all available Oyster commands", cmd_help);
Oyster_register_command("ls", "List files in current volume", cmd_ls);
Oyster_register_command("cat", "Display file contents", cmd_cat);
Oyster_register_command("grep", "Search pattern in file line-by-line", cmd_grep);
Oyster_register_command("rm", "Remove/delete specified file", cmd_rm);
Oyster_register_command("mkdir", "Create a new directory", cmd_mkdir);
Oyster_register_command("rmdir", "Remove an empty directory", cmd_rmdir);
Oyster_register_command("mv", "Move or rename a file/directory", cmd_mv);
Oyster_register_command("cd", "Change current directory", cmd_cd);
Oyster_register_command("pwd", "Print current directory path", cmd_pwd);
Oyster_register_command("echo", "Print argument text to output", cmd_echo);
Oyster_register_command("clear", "Clear terminal screen", cmd_clear);
Oyster_register_command("exit", "Exit Oyster and return to Graphical Shell", cmd_exit);
Oyster_register_command("startmnde", "Exit Oyster and return to Graphical Shell", cmd_exit);
Oyster_register_command("mname", "Shows everything about M.I.L.L.A. OS", cmd_mname);
Oyster_register_command("startn", "Exit Oyster and return to Graphical Shell", cmd_exit);
}
// ============================================================================
// MAIN Oyster LOOP & ENTRY POINT
// ============================================================================
extern "C" void start_cli() {
Oyster_init_font();
Oyster_init_commands();
Oyster_clear();
Oyster_println("===============================================================================");
Oyster_println(" Oyster - Milla OS Command Line ");
Oyster_println("===============================================================================");
Oyster_println("Type 'help' for a list of available commands.");
Oyster_println("Press F12 or type 'exit' to switch back to the Graphical Shell.\n");
Oyster_running = true;
char input_buffer[256];
int input_pos = 0;
input_buffer[0] = '\0';
bool shift_pressed = false;
Oyster_print("o> ");
while (Oyster_running) {
uint8_t sc = get_keyboard_input_nonblock();
if (sc == 0) {
continue;
}
// F12 key (scancode 0x58) -> exit Oyster
if (sc == 0x58) {
Oyster_running = false;
break;
}
// Shift key press / release
if (sc == 0x2A || sc == 0x36) {
shift_pressed = true;
continue;
} else if (sc == (0x2A | 0x80) || sc == (0x36 | 0x80)) {
shift_pressed = false;
continue;
}
// Key release filter
if (sc & 0x80)
continue;
// Backspace (scancode 0x0E)
if (sc == 0x0E) {
if (input_pos > 0) {
input_pos--;
input_buffer[input_pos] = '\0';
Oyster_putchar('\b');
}
continue;
}
// Enter key (scancode 0x1C)
if (sc == 0x1C) {
Oyster_putchar('\n');
input_buffer[input_pos] = '\0';
if (input_pos > 0) {
// Parse arguments
char *argv[16];
int argc = 0;
char *p = input_buffer;
while (*p && argc < 16) {
while (*p == ' ') p++;
if (*p == '\0') break;
argv[argc++] = p;
while (*p && *p != ' ') p++;
if (*p == ' ') {
*p = '\0';
p++;
}
}
if (argc > 0) {
bool found = false;
for (int i = 0; i < Oyster_command_count; i++) {
if (Oyster_strcmp(Oyster_commands[i].name, argv[0])) {
Oyster_commands[i].func(argc, argv);
found = true;
break;
}
}
if (!found) {
Oyster_printf("Command not found: %s. Type 'help' for available commands.\n", argv[0]);
}
}
}
input_pos = 0;
input_buffer[0] = '\0';
if (Oyster_running) {
Oyster_print("o> ");
}
continue;
}
// ASCII character input
char ascii = shell_scancode_to_ascii(sc, shift_pressed);
if (ascii >= 32 && ascii <= 126) {
if (input_pos < (int)sizeof(input_buffer) - 1) {
input_buffer[input_pos++] = ascii;
input_buffer[input_pos] = '\0';
Oyster_putchar(ascii);
}
}
}
Oyster_println("\nExiting Oyster mode...");
delay(100);
}