From 0abe4974df67327bda20ed2ba795571516144d01 Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Wed, 20 Aug 2025 21:54:26 -0700 Subject: [PATCH] made the renderer escapecode based --- includes/tart.h | 5 ++++- source/tart.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/includes/tart.h b/includes/tart.h index 847e57f..9cc57bc 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -22,16 +22,19 @@ extern "C" { #ifdef TART_RGB_COLORS #define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0} -#define TART_CELL_DATA_SIZE 16 // todo add number +#define TART_CELL_DATA_SIZE 32 // todo add number +typedef char tart_display[2]; #else #define NULL_CELL (struct tart_cell){0,0,0,' '} #define TART_CELL_DATA_SIZE 20 +typedef char tart_display; #endif #define TART_OK 0 #define TART_STYLE_BOLD 1 #define TART_STYLE_DIM 2 +#define TART_STYLE_ITALIC 3 #define TART_STYLE_UNDERLINE 4 #define TART_STYLE_BLINKING 5 #define TART_STYLE_INVERSE 7 diff --git a/source/tart.c b/source/tart.c index 270a2b6..aa48ea7 100644 --- a/source/tart.c +++ b/source/tart.c @@ -103,22 +103,44 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { for (int b = 0;b < 0xFF; b++) { if(window->buffers[b].cell_count == 0) continue; + char bufferSetPre[16]; + int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x); + for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) { + //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; + window->data[offset] = bufferSetPre[preIdx]; + offset++; + } + offset++; bufferWidth = window->buffers[b].size.x; for (int y = 0; y < window->buffers[b].size.y; y++) { + char movePre[16]; + int moveSize = sprintf(movePre, "\033[%dB\033[%dG", 1, window->buffers[b].position.x); + for(int preIdx = 0; preIdx < moveSize; preIdx++) { + //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; + window->data[offset] = movePre[preIdx]; + offset++; + } for (int x = 0; x < window->buffers[b].size.x; x++) { // add data to window c buffer. struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; - char pre[TART_CELL_DATA_SIZE]; // puts cell drawing data in pre - int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m", +#ifdef TART_RGB_COLORS + char pre[TART_CELL_DATA_SIZE+4]; + int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m", + // TODO add rgb + (int)cell.style, cell.foreground, + cell.background, cell.display) -1; +#endif + char pre[TART_CELL_DATA_SIZE+4]; + int size = sprintf(pre, "\033[0m\033[%d;%d;%dm%c\033[0;0m", (int)cell.style, cell.foreground, cell.background, cell.display) -1; for(int preIdx = 0; preIdx < size; preIdx++) { - window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx]; + window->data[offset] = pre[preIdx]; offset++; } } - //window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n'; + offset++;