diff options
| -rw-r--r-- | framebuffer.c | 11 | ||||
| -rw-r--r-- | framebuffer.h | 4 |
2 files changed, 8 insertions, 7 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)) diff --git a/framebuffer.h b/framebuffer.h index 6191f2c..4bba181 100644 --- a/framebuffer.h +++ b/framebuffer.h @@ -44,8 +44,8 @@ typedef struct Pixel_s { typedef struct Framebuffer_s { Pixel **fb; /* Adressed as fb[row][col] or fb[x][y] */ size_t width, height; - char *print_buf; /* is of size (42 * width * height) - * 42 is ANSI 24-bit fg and bg + one wchar_t */ + char *print_buf; /* is of size ((38 + sizeof(wchar_t)) * width * height) + * ^^^^^^^^^^^^^^^^^^^^^^ is ANSI 24-bit fg and bg + one wchar_t */ } Framebuffer; /* Check if fb == NULL in case malloc() fails */ |
