summaryrefslogtreecommitdiff
path: root/framebuffer.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-06-29 18:21:17 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-06-29 18:21:17 +0300
commitdfdb1a802028debd5451c1c8acaf75ea1e949102 (patch)
tree17185e339f75af227af27a10677437710dcb9a87 /framebuffer.c
parent28b277fbd8a8a9e1e0e190e608ff193118f5fd1f (diff)
downloadwafflestone-dfdb1a802028debd5451c1c8acaf75ea1e949102.tar.xz
Add UTF-16 compatibility
Diffstat (limited to 'framebuffer.c')
-rw-r--r--framebuffer.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/framebuffer.c b/framebuffer.c
index 1b8439d..32c0f0f 100644
--- a/framebuffer.c
+++ b/framebuffer.c
@@ -32,7 +32,7 @@ Framebuffer fb_new(size_t width, size_t height) {
}
}
- fb.print_buf = malloc(42 * width * height);
+ fb.print_buf = malloc((38 + sizeof(wchar_t)) * width * height);
if (fb.print_buf == NULL) {
/* FIXME: see above */
fb.fb = NULL;
@@ -155,14 +155,15 @@ void term_update_size(void) {
* This is faster than sprinf().
* TODO: maybe less memcpy()s will be better? */
static inline void pixel_to_ascii(char *buf, Pixel p) {
- memcpy(buf, "\x1b[38;2;XXX;XXX;XXXm\x1b[48;2;XXX;XXX;XXXmXXXX", 42);
+ /* Works even on W*ndows with their stupid UTF-16, I think (not tested lmao) */
+ memcpy(buf, "\x1b[38;2;XXX;XXX;XXXm\x1b[48;2;XXX;XXX;XXXmXXXX", 38 + sizeof(wchar_t));
memcpy(buf + 7, uint8toa[p.fg.r], 3);
memcpy(buf + 11, uint8toa[p.fg.g], 3);
memcpy(buf + 15, uint8toa[p.fg.b], 3);
memcpy(buf + 26, uint8toa[p.bg.r], 3);
memcpy(buf + 30, uint8toa[p.bg.g], 3);
memcpy(buf + 34, uint8toa[p.bg.b], 3);
- memcpy(buf + 38, &p.ch, 4);
+ memcpy(buf + 38, &p.ch, sizeof(wchar_t));
}
void fb_print(Framebuffer fb) {
@@ -176,12 +177,12 @@ void fb_print(Framebuffer fb) {
for (size_t row = 0; row < fb.height; row++) {
for (size_t col = 0; col < fb.width; col++) {
pixel_to_ascii(cur, fb.fb[row][col]);
- cur += 42;
+ cur += 38 + sizeof(wchar_t);
}
}
/* flush the buffer */
- write(STDOUT_FILENO, fb.print_buf, 42 * fb.width * fb.height);
+ write(STDOUT_FILENO, fb.print_buf, (38 + sizeof(wchar_t)) * fb.width * fb.height);
}
__attribute__((unused))