summaryrefslogtreecommitdiff
path: root/framebuffer.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-06-21 15:01:30 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-06-21 15:01:30 +0300
commitcb49c9bfa880464862b99d9b7a47a927552989d4 (patch)
tree5528753165c97c3b2461f85d045eae34c84ddbb0 /framebuffer.c
parent3fed5969034c464e36358fc45a99b57b1f308c11 (diff)
downloadwafflestone-cb49c9bfa880464862b99d9b7a47a927552989d4.tar.xz
Output
Diffstat (limited to 'framebuffer.c')
-rw-r--r--framebuffer.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/framebuffer.c b/framebuffer.c
index 66b8c2f..7199052 100644
--- a/framebuffer.c
+++ b/framebuffer.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
@@ -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);
}