add: hold down key && core: create get_key to simplify keyboard usage
This commit is contained in:
@ -1,53 +1,29 @@
|
||||
#include "keyboard.h"
|
||||
#include "drivers.h"
|
||||
#include "interrupts.h"
|
||||
#include "kprintf.h"
|
||||
#include "shell.h"
|
||||
#include "string.h"
|
||||
#include "terminal.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern struct screen *screen;
|
||||
|
||||
int line_status = READING;
|
||||
static bool new_input_indicator = false;
|
||||
static struct key_event new_input = {};
|
||||
|
||||
void keyboard_handler(struct registers *regs)
|
||||
{
|
||||
size_t i = 0;
|
||||
struct key_event ev;
|
||||
|
||||
(void)regs;
|
||||
ev = terminal_getkey();
|
||||
char *buf = screen->line;
|
||||
i = strlen(screen->line);
|
||||
if (ev.c == '\n') {
|
||||
kprintf("\n");
|
||||
screen->line[i] = '\0';
|
||||
line_status = NEWLINE;
|
||||
return;
|
||||
}
|
||||
const size_t size = sizeof(screen->line);
|
||||
if (ev.scan_code == KEY_BACKSPACE && i) {
|
||||
buf[--i] = '\0';
|
||||
move_cursor(LEFT);
|
||||
terminal_putchar(' ');
|
||||
move_cursor(LEFT);
|
||||
} else if (ev.scan_code == KEY_TAB && i) {
|
||||
auto_complete();
|
||||
} else if (ev.c && i < size - 1) {
|
||||
kprintf("%c", ev.c);
|
||||
buf[i++] = ev.c;
|
||||
}
|
||||
if (i >= size) {
|
||||
kprintf("\n");
|
||||
screen->line[i] = '\0';
|
||||
line_status = NEWLINE;
|
||||
}
|
||||
new_input_indicator = true;
|
||||
new_input = terminal_getkey();
|
||||
}
|
||||
|
||||
char *get_line(void)
|
||||
struct key_event get_key(void)
|
||||
{
|
||||
while (line_status != NEWLINE)
|
||||
|
||||
while (!new_input_indicator)
|
||||
;
|
||||
line_status = READING;
|
||||
return screen->line;
|
||||
new_input_indicator = false;
|
||||
return new_input;
|
||||
}
|
Reference in New Issue
Block a user