Commit: 373a83594cc3420de2687c1df6e82572c7c67fbc
Parent: f329ac43b51dc3df831fc59b4bef055a6b585a9d
Author: Randy Palamar
Date: Fri, 15 Nov 2024 08:49:00 -0700
vtgl_handle_keys: write through the platform instead of directly
Diffstat:
3 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/os_unix.c b/os_unix.c
@@ -270,18 +270,6 @@ os_child_exited(iptr pid)
}
static void
-os_child_put_s8(iptr c, s8 text)
-{
- write(c, text.data, text.len);
-}
-
-static void
-os_child_put_char(iptr c, u32 cp)
-{
- os_child_put_s8(c, utf8_encode(cp));
-}
-
-static void
os_set_term_size(iptr child, u32 rows, u32 cols, i32 x, i32 y)
{
struct winsize ws;
diff --git a/vtgl.c b/vtgl.c
@@ -758,7 +758,9 @@ KEYBIND_FN(zoom)
DEBUG_EXPORT VTGL_HANDLE_KEYS_FN(vtgl_handle_keys)
{
- Term *t = memory->memory;
+ Term *t = memory->memory;
+ PlatformAPI *platform = &memory->platform_api;
+ iptr child = t->child;
#ifdef _DEBUG
if (key == KEY_F1 && action == ACT_PRESS) {
@@ -793,12 +795,11 @@ DEBUG_EXPORT VTGL_HANDLE_KEYS_FN(vtgl_handle_keys)
/* TODO: this is wrong. look up where 8-bit modifiers should be sent */
if (0 && t->gl.mode & WIN_MODE_8BIT) {
if (key < 0x7F) {
- s8 enc = utf8_encode(key | 0x80);
- os_child_put_s8(t->child, enc);
+ platform->write(child, utf8_encode(key | 0x80), 0);
return;
}
} else if (BETWEEN(key, 0x40, 0x5F)) {
- os_child_put_char(t->child, key - 0x40);
+ platform->write(child, utf8_encode(key - 0x40), 0);
return;
}
}
@@ -807,59 +808,59 @@ DEBUG_EXPORT VTGL_HANDLE_KEYS_FN(vtgl_handle_keys)
switch (ENCODE_KEY(action, 0, key)) {
case ENCODE_KEY(ACT_PRESS, 0, KEY_ESCAPE):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_ESCAPE):
- os_child_put_char(t->child, 0x1B);
+ platform->write(child, s8("\x1B"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_TAB):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_TAB):
- os_child_put_char(t->child, '\t');
+ platform->write(child, s8("\t"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_ENTER):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_ENTER):
- os_child_put_char(t->child, '\r');
+ platform->write(child, s8("\r"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_BACKSPACE):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_BACKSPACE):
- os_child_put_char(t->child, 0x7F);
+ platform->write(child, s8("\x7F"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_UP):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_UP):
if (t->gl.mode & WIN_MODE_APPCURSOR)
- os_child_put_s8(t->child, s8("\x1BOA"));
+ platform->write(child, s8("\x1BOA"), 0);
else
- os_child_put_s8(t->child, s8("\x1B[A"));
+ platform->write(child, s8("\x1B[A"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_DOWN):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_DOWN):
if (t->gl.mode & WIN_MODE_APPCURSOR)
- os_child_put_s8(t->child, s8("\x1BOB"));
+ platform->write(child, s8("\x1BOB"), 0);
else
- os_child_put_s8(t->child, s8("\x1B[B"));
+ platform->write(child, s8("\x1B[B"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_RIGHT):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_RIGHT):
if (t->gl.mode & WIN_MODE_APPCURSOR)
- os_child_put_s8(t->child, s8("\x1BOC"));
+ platform->write(child, s8("\x1BOC"), 0);
else
- os_child_put_s8(t->child, s8("\x1B[C"));
+ platform->write(child, s8("\x1B[C"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_LEFT):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_LEFT):
if (t->gl.mode & WIN_MODE_APPCURSOR)
- os_child_put_s8(t->child, s8("\x1BOD"));
+ platform->write(child, s8("\x1BOD"), 0);
else
- os_child_put_s8(t->child, s8("\x1B[D"));
+ platform->write(child, s8("\x1B[D"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_PAGE_UP):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_PAGE_UP):
- if (modifiers & MOD_CONTROL) os_child_put_s8(t->child, s8("\x1B[5;5~"));
- else if (modifiers & MOD_SHIFT) os_child_put_s8(t->child, s8("\x1B[5;2~"));
- else os_child_put_s8(t->child, s8("\x1B[5~"));
+ if (modifiers & MOD_CONTROL) platform->write(child, s8("\x1B[5;5~"), 0);
+ else if (modifiers & MOD_SHIFT) platform->write(child, s8("\x1B[5;2~"), 0);
+ else platform->write(child, s8("\x1B[5~"), 0);
break;
case ENCODE_KEY(ACT_PRESS, 0, KEY_PAGE_DOWN):
case ENCODE_KEY(ACT_REPEAT, 0, KEY_PAGE_DOWN):
- if (modifiers & MOD_CONTROL) os_child_put_s8(t->child, s8("\x1B[6;5~"));
- else if (modifiers & MOD_SHIFT) os_child_put_s8(t->child, s8("\x1B[6;2~"));
- else os_child_put_s8(t->child, s8("\x1B[6~"));
+ if (modifiers & MOD_CONTROL) platform->write(child, s8("\x1B[6;5~"), 0);
+ else if (modifiers & MOD_SHIFT) platform->write(child, s8("\x1B[6;2~"), 0);
+ else platform->write(child, s8("\x1B[6~"), 0);
break;
}
}
diff --git a/vtgl.h b/vtgl.h
@@ -234,8 +234,6 @@ typedef struct TerminalMemory {
u64 debug_memory_size;
void *debug_memory;
- iptr child;
-
PlatformAPI platform_api;
} TerminalMemory;