frontend: add a line editor for shell input

This commit is contained in:
2024-11-18 09:53:55 +00:00
parent f44a3364b3
commit 4fc1a6ade8
22 changed files with 2137 additions and 0 deletions

37
frontend/line-ed/hook.c Normal file
View File

@@ -0,0 +1,37 @@
#include "hook.h"
#include "line-ed.h"
void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook)
{
b_queue_push_back(&ed->l_hooks, &hook->hook_entry);
}
void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook)
{
b_queue_delete(&ed->l_hooks, &hook->hook_entry);
}
void hook_keypress(struct line_ed *ed, s_keycode key)
{
b_queue_iterator it;
b_queue_foreach (&it, &ed->l_hooks) {
struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, it.entry, hook_entry);
if (hook->hook_keypress) {
hook->hook_keypress(ed, hook, key);
}
}
}
void hook_buffer_modified(struct line_ed *ed)
{
b_queue_iterator it;
b_queue_foreach (&it, &ed->l_hooks) {
struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, it.entry, hook_entry);
if (hook->hook_buffer_modified) {
hook->hook_buffer_modified(ed, hook);
}
}
}