Kernel: Add clear() command public TTY API

This commit is contained in:
Bananymous 2022-12-13 10:45:24 +02:00
parent e62a626b39
commit 68e88d9413
2 changed files with 48 additions and 10 deletions

View File

@ -7,6 +7,7 @@ namespace TTY
void initialize(); void initialize();
void putchar(char c); void putchar(char c);
void clear();
void write(const char* data, size_t size); void write(const char* data, size_t size);
void writestring(const char* data); void writestring(const char* data);
void set_cursor_pos(int x, int y); void set_cursor_pos(int x, int y);

View File

@ -20,24 +20,57 @@
multiboot_info_t* s_multiboot_info; multiboot_info_t* s_multiboot_info;
void on_key_press(Keyboard::Key key, uint8_t modifiers, bool pressed) char ascii_buffer[32] {};
static bool has_command(const char* cmd)
{ {
if (pressed) size_t len = strlen(cmd);
return memcmp(ascii_buffer + sizeof(ascii_buffer) - len - 1, cmd, len) == 0;
}
void on_key_press(Keyboard::KeyEvent event)
{
if (event.pressed)
{ {
if (key == Keyboard::Key::Escape) char ascii = Keyboard::key_event_to_ascii(event);
if (ascii)
{
memmove(ascii_buffer, ascii_buffer + 1, sizeof(ascii_buffer) - 1);
ascii_buffer[sizeof(ascii_buffer) - 1] = ascii;
kprint("{}", ascii);
}
if (event.key == Keyboard::Key::Escape)
{ {
kprint("time since boot: {} ms\n", PIT::ms_since_boot()); kprint("time since boot: {} ms\n", PIT::ms_since_boot());
return; return;
} }
else if (key == Keyboard::Key::Backspace) else if (event.key == Keyboard::Key::Backspace)
{ {
kprint("\b \b"); memmove(ascii_buffer + 2, ascii_buffer, sizeof(ascii_buffer) - 2);
kprint(" \b");
} }
else else if (event.key == Keyboard::Key::Enter)
{ {
char ascii = Keyboard::key_to_ascii(key, modifiers); if (has_command("clear"))
if (ascii) {
kprint("{}", ascii); TTY::clear();
TTY::set_cursor_pos(0, 0);
}
else if (has_command("led_disco"))
{
TTY::clear();
TTY::set_cursor_pos(0, 0);
kprintln("\e[32mLED DISCO\e[m");
Keyboard::led_disco();
}
else if (has_command("reboot"))
{
uint8_t good = 0x02;
while (good & 0x02)
good = IO::inb(0x64);
IO::outb(0x64, 0xFE);
asm volatile("cli; hlt");
}
} }
} }
} }
@ -52,8 +85,12 @@ void kernel_main(multiboot_info_t* mbi, uint32_t magic)
if (magic != 0x2BADB002) if (magic != 0x2BADB002)
return; return;
TTY::initialize();
Serial::initialize(); Serial::initialize();
TTY::initialize();
for (int i = 30; i <= 37; i++)
kprint("\e[{}m#", i);
kprint("\e[m\n");
kmalloc_initialize(); kmalloc_initialize();