mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 10:26:59 +00:00
CMD config
This commit is contained in:
83
src/kernel/userland/about.c
Normal file
83
src/kernel/userland/about.c
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright (c) 2023-2026 Chris (boreddevnl)
|
||||
// This software is released under the GNU General Public License v3.0. See LICENSE file for details.
|
||||
// This header needs to maintain in any file it is present in, as per the GPL license terms.
|
||||
#include "syscall.h"
|
||||
#include "libui.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static void draw_boredos_logo(ui_window_t win, int x, int y, int scale) {
|
||||
static const uint8_t brewos_bmp[] = {
|
||||
0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,
|
||||
0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,
|
||||
1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,
|
||||
1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,
|
||||
1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,
|
||||
1,1,2,2,2,1,1,2,2,1,1,2,2,2,1,1,
|
||||
1,1,2,2,1,1,1,1,1,1,1,1,2,2,1,1,
|
||||
1,1,2,2,1,1,1,1,1,1,1,1,2,2,1,1,
|
||||
1,1,2,2,1,1,1,1,1,1,1,1,2,2,1,1,
|
||||
1,1,2,2,2,1,1,2,2,1,1,2,2,2,1,1,
|
||||
1,1,2,2,2,2,2,1,1,2,2,2,2,2,1,1,
|
||||
1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,
|
||||
1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,
|
||||
0,1,1,1,2,2,2,2,2,2,2,2,1,1,1,0,
|
||||
0,0,1,1,1,2,2,2,2,2,2,1,1,1,0,0,
|
||||
0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0
|
||||
};
|
||||
|
||||
for (int r = 0; r < 16; r++) {
|
||||
for (int c = 0; c < 16; c++) {
|
||||
uint8_t p = brewos_bmp[r * 16 + c];
|
||||
if (p == 1) {
|
||||
ui_draw_rect(win, x + c * scale, y + r * scale, scale, scale, 0xFF1A1A1A);
|
||||
} else if (p == 2) {
|
||||
ui_draw_rect(win, x + c * scale, y + r * scale, scale, scale, 0xFFFEFEFE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void about_paint(ui_window_t win) {
|
||||
int w = 185;
|
||||
int h = 240;
|
||||
|
||||
//ui_draw_rect(win, 0, 0, w, h, 0xFF1E1E1E);
|
||||
|
||||
int offset_x = 15;
|
||||
int offset_y = 35;
|
||||
|
||||
draw_boredos_logo(win, 60, offset_y, 4);
|
||||
|
||||
// Version info
|
||||
ui_draw_string(win, offset_x, offset_y + 105, "BoredOS 'Panda'", 0xFFFFFFFF);
|
||||
ui_draw_string(win, offset_x, offset_y + 120, "BoredOS Version 1.64", 0xFFFFFFFF);
|
||||
ui_draw_string(win, offset_x, offset_y + 135, "Kernel Version 3.0.0", 0xFFFFFFFF);
|
||||
|
||||
// Copyright
|
||||
ui_draw_string(win, offset_x, offset_y + 150, "(C) 2026 boreddevnl.", 0xFFFFFFFF);
|
||||
ui_draw_string(win, offset_x, offset_y + 165, "All rights reserved.", 0xFFFFFFFF);
|
||||
|
||||
ui_mark_dirty(win, 0, 0, w, h);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
ui_window_t win_about = ui_window_create("About BoredOS", 250, 180, 185, 240);
|
||||
|
||||
about_paint(win_about);
|
||||
|
||||
gui_event_t ev;
|
||||
while (1) {
|
||||
if (ui_get_event(win_about, &ev)) {
|
||||
if (ev.type == GUI_EVENT_PAINT) {
|
||||
about_paint(win_about);
|
||||
} else if (ev.type == GUI_EVENT_CLOSE) {
|
||||
sys_exit(0);
|
||||
}
|
||||
} else {
|
||||
// Avoid high CPU usage
|
||||
for(volatile int i=0; i<10000; i++);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <syscall.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint32_t error_color = (uint32_t)sys_get_shell_config("error_color");
|
||||
uint32_t default_color = (uint32_t)sys_get_shell_config("default_text_color");
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: cat <filename>\n");
|
||||
return 1;
|
||||
@@ -12,7 +15,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
int fd = sys_open(argv[1], "r");
|
||||
if (fd < 0) {
|
||||
sys_set_text_color(error_color);
|
||||
printf("Error: Cannot open %s\n", argv[1]);
|
||||
sys_set_text_color(default_color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#define STR_POOL_SIZE 16384
|
||||
|
||||
static int compile_error = 0;
|
||||
static uint32_t color_error = 0xFFFF4444;
|
||||
static uint32_t color_success = 0xFF6A9955;
|
||||
static uint32_t color_default = 0xFFCCCCCC;
|
||||
|
||||
// --- Lexer ---
|
||||
typedef enum {
|
||||
@@ -59,7 +62,9 @@ static Token tokens[MAX_TOKENS];
|
||||
static int token_count = 0;
|
||||
|
||||
static void lex_error(const char *msg) {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Compiler Error: %s\n", msg);
|
||||
sys_set_text_color(color_default);
|
||||
compile_error = 1;
|
||||
}
|
||||
|
||||
@@ -304,7 +309,12 @@ static int add_symbol(const char *name) {
|
||||
|
||||
static void emit(uint8_t b) {
|
||||
if (code_pos < CODE_SIZE) code[code_pos++] = b;
|
||||
else { printf("Error: Code buffer overflow\n"); compile_error = 1; }
|
||||
else {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Error: Code buffer overflow\n");
|
||||
sys_set_text_color(color_default);
|
||||
compile_error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void emit32(int v) {
|
||||
@@ -323,7 +333,12 @@ static int add_string(const char *str) {
|
||||
static void match(TokenType t) {
|
||||
if (compile_error) return;
|
||||
if (tokens[cur_token].type == t) cur_token++;
|
||||
else { printf("Syntax Error: Expected token %d got %d\n", t, tokens[cur_token].type); compile_error = 1; }
|
||||
else {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Syntax Error: Expected token %d got %d\n", t, tokens[cur_token].type);
|
||||
sys_set_text_color(color_default);
|
||||
compile_error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void expression();
|
||||
@@ -352,11 +367,21 @@ static void factor() {
|
||||
if (syscall != -1 && tokens[cur_token+1].type == TOK_LPAREN) function_call(syscall);
|
||||
else {
|
||||
int addr = find_symbol(tokens[cur_token].str_val);
|
||||
if (addr == -1) { printf("Error: Undefined variable: %s\n", tokens[cur_token].str_val); compile_error = 1; }
|
||||
if (addr == -1) {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Error: Undefined variable: %s\n", tokens[cur_token].str_val);
|
||||
sys_set_text_color(color_default);
|
||||
compile_error = 1;
|
||||
}
|
||||
emit(OP_LOAD); emit32(addr); cur_token++;
|
||||
}
|
||||
} else if (tokens[cur_token].type == TOK_LPAREN) { cur_token++; expression(); match(TOK_RPAREN); }
|
||||
else { printf("Syntax Error: Unexpected token in factor\n"); compile_error = 1; }
|
||||
else {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Syntax Error: Unexpected token in factor\n");
|
||||
sys_set_text_color(color_default);
|
||||
compile_error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void term() {
|
||||
@@ -461,10 +486,19 @@ static void program() {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
color_error = (uint32_t)sys_get_shell_config("error_color");
|
||||
color_success = (uint32_t)sys_get_shell_config("success_color");
|
||||
color_default = (uint32_t)sys_get_shell_config("default_text_color");
|
||||
|
||||
if (argc < 2) { printf("Usage: cc <filename.c>\n"); return 1; }
|
||||
|
||||
int fh = sys_open(argv[1], "r");
|
||||
if (fh < 0) { printf("Error: Cannot open source file.\n"); return 1; }
|
||||
if (fh < 0) {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Error: Cannot open source file.\n");
|
||||
sys_set_text_color(color_default);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *source = (char*)malloc(MAX_SOURCE);
|
||||
if (!source) { printf("Error: Out of memory for source buffer.\n"); sys_close(fh); return 1; }
|
||||
@@ -515,8 +549,14 @@ int main(int argc, char **argv) {
|
||||
if (out_fh >= 0) {
|
||||
sys_write_fs(out_fh, code, code_pos);
|
||||
sys_close(out_fh);
|
||||
sys_set_text_color(color_success);
|
||||
printf("Compilation successful. Output: %s\n", out_name);
|
||||
} else { printf("Error: Cannot write output file.\n"); }
|
||||
sys_set_text_color(color_default);
|
||||
} else {
|
||||
sys_set_text_color(color_error);
|
||||
printf("Error: Cannot write output file.\n");
|
||||
sys_set_text_color(color_default);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc; (void)argv;
|
||||
uint32_t help_color = sys_get_shell_config("help_color");
|
||||
if (help_color != 0) sys_set_text_color(help_color);
|
||||
|
||||
printf("BoredOS CLI Help\n");
|
||||
printf("---------------------------\n");
|
||||
printf("ls [path] - List directory contents\n");
|
||||
|
||||
@@ -179,3 +179,11 @@ int sys_network_is_initialized(void) {
|
||||
return (int)syscall2(SYS_SYSTEM, SYSTEM_CMD_NETWORK_IS_INIT, 0);
|
||||
}
|
||||
|
||||
uint64_t sys_get_shell_config(const char *key) {
|
||||
return (uint64_t)sys_system(SYSTEM_CMD_GET_SHELL_CONFIG, (uint64_t)key, 0, 0, 0);
|
||||
}
|
||||
|
||||
void sys_set_text_color(uint32_t color) {
|
||||
sys_system(SYSTEM_CMD_SET_TEXT_COLOR, (uint64_t)color, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
#define SYSTEM_CMD_NETWORK_GET_DNS 25
|
||||
#define SYSTEM_CMD_ICMP_PING 26
|
||||
#define SYSTEM_CMD_NETWORK_IS_INIT 27
|
||||
#define SYSTEM_CMD_GET_SHELL_CONFIG 28
|
||||
#define SYSTEM_CMD_SET_TEXT_COLOR 29
|
||||
|
||||
// Internal assembly entry into Ring 0
|
||||
extern uint64_t syscall0(uint64_t sys_num);
|
||||
@@ -113,4 +115,7 @@ int sys_udp_send(const net_ipv4_address_t *dest_ip, uint16_t dest_port, uint16_t
|
||||
int sys_icmp_ping(const net_ipv4_address_t *dest_ip);
|
||||
int sys_network_is_initialized(void);
|
||||
|
||||
uint64_t sys_get_shell_config(const char *key);
|
||||
void sys_set_text_color(uint32_t color);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,12 +5,18 @@
|
||||
#include <syscall.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint32_t dir_color = (uint32_t)sys_get_shell_config("dir_color");
|
||||
uint32_t file_color = (uint32_t)sys_get_shell_config("file_color");
|
||||
uint32_t size_color = (uint32_t)sys_get_shell_config("size_color");
|
||||
uint32_t error_color = (uint32_t)sys_get_shell_config("error_color");
|
||||
uint32_t default_color = (uint32_t)sys_get_shell_config("default_text_color");
|
||||
|
||||
char path[256];
|
||||
if (argc > 1) {
|
||||
strcpy(path, argv[1]);
|
||||
} else {
|
||||
if (!getcwd(path, sizeof(path))) {
|
||||
strcpy(path, ".");
|
||||
if (!sys_getcwd(path, sizeof(path))) {
|
||||
strcpy(path, "/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +24,25 @@ int main(int argc, char **argv) {
|
||||
int count = sys_list(path, entries, 128);
|
||||
|
||||
if (count < 0) {
|
||||
sys_set_text_color(error_color);
|
||||
printf("Error: Cannot list directory %s\n", path);
|
||||
sys_set_text_color(default_color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (entries[i].is_directory) {
|
||||
sys_set_text_color(dir_color);
|
||||
printf("[DIR] %s\n", entries[i].name);
|
||||
} else {
|
||||
printf("[FILE] %s (%d bytes)\n", entries[i].name, entries[i].size);
|
||||
sys_set_text_color(file_color);
|
||||
printf("[FILE] %s", entries[i].name);
|
||||
sys_set_text_color(size_color);
|
||||
printf(" (%d bytes)\n", entries[i].size);
|
||||
}
|
||||
}
|
||||
|
||||
sys_set_text_color(default_color);
|
||||
printf("\nTotal: %d items\n", count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,16 +5,24 @@
|
||||
#include <syscall.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint32_t error_color = (uint32_t)sys_get_shell_config("error_color");
|
||||
uint32_t success_color = (uint32_t)sys_get_shell_config("success_color");
|
||||
uint32_t default_color = (uint32_t)sys_get_shell_config("default_text_color");
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: mkdir <dirname>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sys_mkdir(argv[1]) == 0) {
|
||||
sys_set_text_color(success_color);
|
||||
printf("Created directory: %s\n", argv[1]);
|
||||
} else {
|
||||
sys_set_text_color(error_color);
|
||||
printf("Error: Cannot create directory %s\n", argv[1]);
|
||||
sys_set_text_color(default_color);
|
||||
return 1;
|
||||
}
|
||||
sys_set_text_color(default_color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include <syscall.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint32_t error_color = (uint32_t)sys_get_shell_config("error_color");
|
||||
uint32_t success_color = (uint32_t)sys_get_shell_config("success_color");
|
||||
uint32_t default_color = (uint32_t)sys_get_shell_config("default_text_color");
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: rm <path>\n");
|
||||
return 1;
|
||||
@@ -12,10 +16,14 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Simple rm (no recursive support yet for simplicity, but can be added)
|
||||
if (sys_delete(argv[1]) == 0) {
|
||||
sys_set_text_color(success_color);
|
||||
printf("Deleted: %s\n", argv[1]);
|
||||
} else {
|
||||
sys_set_text_color(error_color);
|
||||
printf("Error: Cannot delete %s\n", argv[1]);
|
||||
sys_set_text_color(default_color);
|
||||
return 1;
|
||||
}
|
||||
sys_set_text_color(default_color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user