From cb49c9bfa880464862b99d9b7a47a927552989d4 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sun, 21 Jun 2026 15:01:30 +0300 Subject: Output --- framebuffer.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'framebuffer.c') diff --git a/framebuffer.c b/framebuffer.c index 66b8c2f..7199052 100644 --- a/framebuffer.c +++ b/framebuffer.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -50,12 +51,12 @@ ret: void fb_fill(Framebuffer fb, Pixel pixel) { for (size_t row = 0; row < fb.height; row++) { for (size_t col = 0; col < fb.width; col++) { - fb_put(fb, row, col, pixel); + fb.fb[row][col] = pixel; } } } -void inline fb_put(Framebuffer fb, size_t row, size_t col, Pixel pixel) { +void fb_put(Framebuffer fb, size_t row, size_t col, Pixel pixel) { fb.fb[row][col] = pixel; } @@ -82,6 +83,7 @@ void term_cleanup(void) { write(STDOUT_FILENO, "\x1b[?25h", 6); /* Show the cursor */ write(STDOUT_FILENO, "\x1b[?1049l", 8); /* Alternative screen buffer */ + write(STDOUT_FILENO, "\x1b[0m", 4); /* Reset styling (colour) */ } void term_update_size(void) { @@ -109,5 +111,22 @@ void term_update_size(void) { void fb_print(Framebuffer fb) { write(STDOUT_FILENO, "\x1b[H", 3); /* Move cursor to top-left */ - /* TODO: finish me */ + for (size_t row = 0; row < fb.height; row++) { + for (size_t col = 0; col < fb.width; col++) { + set_fg(fb.fb[row][col].fg); + set_bg(fb.fb[row][col].bg); + write(STDOUT_FILENO, &(fb.fb[row][col].ch), sizeof(wchar_t)); + } + } + fflush(stdout); +} + +static inline void set_fg(Colour col) { + fprintf(stdout, "\x1b[38;2;%u;%u;%um", col.r, col.g, col.g); + fflush(stdout); +} + +static inline void set_bg(Colour col) { + fprintf(stdout, "\x1b[48;2;%u;%u;%um", col.r, col.g, col.g); + fflush(stdout); } -- cgit v1.2.3