From 8a583187160c5bdade9aac13600e9fae7a2b188a Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Tue, 4 Nov 2025 19:49:45 -0500 Subject: fix bug of attrs not being changed properly --- main.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 71d3afc..f59e335 100644 --- a/main.c +++ b/main.c @@ -201,6 +201,9 @@ void vui_init(void) { vui_raw_stdout_tos.c_oflag &= ~OPOST; tcsetattr(STDOUT_FILENO, TCSANOW, &vui_raw_stdout_tos); + /* set white:black to default */ + printf(CSI "40;37m" CSI "8]"); + vui_adjust(); signal(SIGWINCH, vui_on_sigwinch); } @@ -216,9 +219,7 @@ static void free_buf(VuiBuffer *buf) { } static inline int bchr_equiv(VuiBuffer *back, VuiBuffer *front, int x, int y) { - return BCHR(back,x,y) == BCHR(front,x,y) - && (BATTR(back,x,y) == BATTR(front,x,y) - /* || BCHR(back,x,y) == ' ' */); + return BCHR(back,x,y) == BCHR(front,x,y) && (BATTR(back,x,y) == BATTR(front,x,y)); } static char *vui_out = NULL; @@ -283,7 +284,7 @@ static inline void vui_out_flush(void) { fflush(stdout); #if 0 static unsigned out_frame = 0; - FILE *f = fopen("out_log.txt", "a"); + FILE *f = fopen("out_log.txt", "w"); assert(f); fprintf(f, "\n\n:: OUTPUT FRAME %u ::\n", ++out_frame); fwrite(vui_out, 1, vui_outn, f); @@ -322,12 +323,20 @@ static inline void curs_move(int src_x, int src_y, int dst_x, int dst_y) { } } +#define M(s) do {\ + if (sep) vui_outc(';');\ + vui_outs(s);\ + sep = 1;\ +} while(0) + static void attr_chg(VuiAttr *ptr, VuiAttr to) { VuiAttr from = *ptr; if (from == to) return; + int sep = 0; + int attr_chg_count = stdc_count_ones(ATTR_A(from) ^ ATTR_A(to)); - int chg_attr = !!attr_chg_count; + int chg_attr = (attr_chg_count != 0); if (!chg_attr) goto chg_colors; /* deduct color changes */ @@ -347,26 +356,27 @@ static void attr_chg(VuiAttr *ptr, VuiAttr to) { from = ATTR_DEFAULT; assert(ATTR_FG(from) == FG_WHITE); assert(ATTR_BG(from) == BG_BLACK); + sep = 1; } else { vui_outs(CSI); if ((to ^ from) & A_BOLD) { - if (to & A_BOLD) vui_outs(";1"); + if (to & A_BOLD) M("1"); else { - vui_outs(";22"); + M("22"); from &= (~A_BOLD & ~A_DIM); } } if ((to ^ from) & A_DIM) { - if (to & A_BOLD) vui_outs(";2"); + if (to & A_BOLD) M("2"); else { - vui_outs(";22"); + M("22"); from &= (~A_BOLD & ~A_DIM); } } - if ((to ^ from) & A_ITALIC) vui_outs((to & A_ITALIC) ? ";3" : ";23"); - if ((to ^ from) & A_UNDERSCORE) vui_outs((to & A_UNDERSCORE) ? ";4" : ";24"); - if ((to ^ from) & A_BLINK) vui_outs((to & A_BLINK) ? ";5" : ";25"); - if ((to ^ from) & A_REVERSE) vui_outs((to & A_REVERSE) ? ";7" : ";27"); + if ((to ^ from) & A_ITALIC) M((to & A_ITALIC) ? "3" : "23"); + if ((to ^ from) & A_UNDERSCORE) M((to & A_UNDERSCORE) ? "4" : "24"); + if ((to ^ from) & A_BLINK) M((to & A_BLINK) ? "5" : "25"); + if ((to ^ from) & A_REVERSE) M((to & A_REVERSE) ? "7" : "27"); } chg_colors: @@ -411,7 +421,8 @@ void vui_blit(void) { VuiBuffer *back = vui_win.back; vui_outf(CSI "H" CSI "0m"); - VuiAttr attr_last = ATTR_DEFAULT; + //vui_outs(CSI "2J"); + static VuiAttr attr_last = ATTR_DEFAULT; scrolled_x = vui_win.scroll_x; scrolled_y = vui_win.scroll_y; @@ -608,7 +619,7 @@ int dx = 0, dy = 0; int camx = 0, camy = 0; int C = '*'; unsigned frame = 0; -int half_y = 0; +int half_y = 1; void draw(void *ctx) { (void)ctx; @@ -705,7 +716,6 @@ int main(int argc, const char **argv) { for (unsigned x = 0; x < COLS; x++) { int tx = x + camx, ty = y + camy; char ch = " ',."[(tx^ty)&3]; - ch = ' '; VuiAttr a = (((tx>>2)^(ty>>2)) % 3 == 0) ? BG_WHITE : BG_RED; vui_chra(x, y, ch, a); } -- cgit v1.2.3