From fc8bc6a495609f51a3ae25f368fc0910cd49c52f Mon Sep 17 00:00:00 2001 From: Starnakin Date: Wed, 9 Oct 2024 22:10:22 +0200 Subject: [PATCH] add: get_line --- headers/terminal.h | 1 + src/drivers/keyboard.c | 8 ++++++++ src/shell/exec.c | 6 ++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/headers/terminal.h b/headers/terminal.h index 2717d95..0a80268 100644 --- a/headers/terminal.h +++ b/headers/terminal.h @@ -59,3 +59,4 @@ void terminal_set_default_bg_color(uint8_t fg_color); void terminal_change_default_fg_color(uint8_t color); uint8_t terminal_get_default_color(void); uint8_t terminal_get_char(int column, int row); +char *get_line(void); \ No newline at end of file diff --git a/src/drivers/keyboard.c b/src/drivers/keyboard.c index a7b3776..ffceee4 100644 --- a/src/drivers/keyboard.c +++ b/src/drivers/keyboard.c @@ -43,3 +43,11 @@ void keyboard_handler(struct registers *regs) line_status = NEWLINE; } } + +char *get_line(void) +{ + while (line_status != NEWLINE) + ; + line_status = READING; + return screen->line; +} \ No newline at end of file diff --git a/src/shell/exec.c b/src/shell/exec.c index 65c471c..ff16bd3 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -77,10 +77,9 @@ void auto_complete(void) void shell_init(void) { + char *line; kprintf(PROMPT); - while (1) { - if (line_status != NEWLINE) - continue; + while ((line = get_line())) { bool invalid = true; for (unsigned i = 0; i < NB_CMDS; i++) { if (!strncmp(cmds[i].name, screen->line, @@ -97,7 +96,6 @@ void shell_init(void) kprintf(KERN_WARNING "invalid command: %s\n", screen->line); memset(screen->line, '\0', sizeof(screen->line)); - line_status = READING; kprintf(PROMPT); } }