SayoriOS 0.3.3

dino.c
1 #include "common.h"
2 #include "drv/vfs_new.h"
3 #include "drv/input/keyboard.h"
4 #include "gui/basics.h"
5 #include "io/screen.h"
6 #include "io/tty.h"
7 #include "sys/trigger.h"
8 #include "drv/input/keymap.h"
9 #include "lib/string.h"
10 #include "drv/psf.h"
11 #include "io/ports.h"
12
13 char dino_cur_path[1024] = "/";
14 struct dirent* dino_cur_dirent = nullptr;
15 size_t dino_dirent_count = 0;
16 size_t dino_current_selection = 0;
17
18 void dino_draw_back() {
19 draw_filled_rectangle(0, 0, VESA_WIDTH, VESA_HEIGHT, 0x444444);
20 draw_filled_rectangle(40, 40, VESA_WIDTH - 80, VESA_HEIGHT - 80, 0x666666);
21 }
22
23 void dino_draw_panels() {
24
25 }
26
27 void dino_draw_main() {
28 draw_rectangle(
29 50,
30 50 + (dino_current_selection * 16),
31 strlen(dino_cur_dirent[dino_current_selection].name) * 8,
32 16,
33 0x000000
34 );
35
36 // TODO: Scrollable list
37 for(int i = 0; i < dino_dirent_count; i++) {
38 struct dirent elem = dino_cur_dirent[i];
39
40 draw_vga_str(elem.name, strlen(elem.name), 50, 50 + (i * 16), 0x111111);
41 }
42 }
43
44 void dino_update() {
45 dino_cur_dirent = vfs_getListFolder(dino_cur_path);
46 dino_dirent_count = vfs_getCountElemDir(dino_cur_path);
47 }
48
49 void dino_path_check() {
50 // Remove trailing (duplictaing) slashes here.
51
52 size_t len = strlen(dino_cur_path);
53 size_t score = 0;
54
55 for(int i = 0; i < len; i++) {
56 if(dino_cur_path[i] == '/') {
57 score++;
58
59 if(score > 1) {
60 memmove(dino_cur_path + i, dino_cur_path + i + 1, len - i);
61 }
62 } else {
63 score = 0;
64 }
65 }
66 }
67
68 void dino_keyhandler(int key, int pressed, int c, int d, int e) {
69 if (pressed) {
70 if(key == KEY_DOWN)
71 dino_current_selection = ((dino_current_selection + 1) % dino_dirent_count);
72 else if(key == KEY_UP)
73 dino_current_selection = dino_current_selection == 0 ? dino_dirent_count - 1 : dino_current_selection - 1;
74 else if(key == KEY_ENTER) {
75 qemu_log("You selected: %s", dino_cur_dirent[dino_current_selection].name);
76
77 strcat(dino_cur_path, dino_cur_dirent[dino_current_selection].name);
78
79 dino_path_check();
80
81 qemu_log("Path: %s", dino_cur_path);
82
83 dino_current_selection = 0;
84
85 dino_update();
86 }
87 }
88 }
89
90 uint32_t dino_filemanager(int argc, char* argv[]) {
91 dino_update();
92
93 keyboardctl(KEYBOARD_ECHO, false);
94
95 RegTrigger(TRIGGER_KEY_PRESSED, (trigger_cmd_t)dino_keyhandler);
96
97 while(1) {
98 int key = getCharRaw();
99 if(key == KEY_ESC)
100 break;
101
102 dino_draw_back();
103 dino_draw_panels();
104 dino_draw_main();
105
106 punch();
107 }
108
109 clean_tty_screen();
110
111 keyboardctl(KEYBOARD_ECHO, true);
112
113 return 0;
114 }
common.h
Основные определения ядра
strlen
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88
memmove
void * memmove(void *dest, void *src, size_t count)
Копирование массивов (в том числе пересекающихся)
Definition: string.c:220
strcat
char * strcat(char *destination, const char *source)
Объединение строк
Definition: string.c:463
dirent
Согласно POSIX, один из них возвращается вызовом readdir.
Definition: vfs_new.h:77
dirent::name
char name[128]
Имя файла
Definition: vfs_new.h:78
RegTrigger
int RegTrigger(int type, trigger_cmd_t handler)
Регистрация триггера
Definition: trigger.c:35