Kernel: Add clear() command public TTY API
This commit is contained in:
parent
e62a626b39
commit
68e88d9413
|
@ -7,6 +7,7 @@ namespace TTY
|
|||
|
||||
void initialize();
|
||||
void putchar(char c);
|
||||
void clear();
|
||||
void write(const char* data, size_t size);
|
||||
void writestring(const char* data);
|
||||
void set_cursor_pos(int x, int y);
|
||||
|
|
|
@ -20,24 +20,57 @@
|
|||
|
||||
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 (key == Keyboard::Key::Escape)
|
||||
if (event.pressed)
|
||||
{
|
||||
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());
|
||||
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 (ascii)
|
||||
kprint("{}", ascii);
|
||||
if (has_command("clear"))
|
||||
{
|
||||
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)
|
||||
return;
|
||||
|
||||
TTY::initialize();
|
||||
Serial::initialize();
|
||||
TTY::initialize();
|
||||
|
||||
for (int i = 30; i <= 37; i++)
|
||||
kprint("\e[{}m#", i);
|
||||
kprint("\e[m\n");
|
||||
|
||||
kmalloc_initialize();
|
||||
|
||||
|
|
Loading…
Reference in New Issue