From d862b833292133948e67bfd39a20d825bc80733e Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Thu, 1 Jan 2026 04:08:12 -0500 Subject: add FG_DEFAULT/BG_DEFAULT and J to join lines --- vui.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'vui.c') diff --git a/vui.c b/vui.c index 9902707..0c6c071 100644 --- a/vui.c +++ b/vui.c @@ -108,7 +108,7 @@ static void vui_clrspan(VuiBuffer *buf, unsigned x0, unsigned x1, unsigned y) { BCHR(buf, x, y) = ' '; } for (unsigned x = x0; x < x1; x++) { - BATTR(buf, x, y) = ATTR_DEFAULT; + BATTR(buf, x, y) = A_DEFAULT; } } @@ -244,7 +244,6 @@ void vui_redraw(void) { void vui_init(void) { /* set white:black to default */ - printf(CSI "40;37m" CSI "8]"); vui_curs_vis(0); vui_enable(); vui_redraw(); @@ -420,10 +419,10 @@ static void attr_chg(VuiAttr *ptr, VuiAttr to) { if (!chg_attr) goto chg_colors; /* deduct color changes */ - attr_chg_count -= (ATTR_FG(to) == ATTR_FG(from)) && (ATTR_FG(to) != ATTR_DEFAULT); - attr_chg_count -= (ATTR_BG(to) == ATTR_BG(from)) && (ATTR_BG(to) != ATTR_DEFAULT); + attr_chg_count -= (ATTR_FG(to) == ATTR_FG(from)) && (ATTR_FG(to) != FG_DEFAULT); + attr_chg_count -= (ATTR_BG(to) == ATTR_BG(from)) && (ATTR_BG(to) != FG_DEFAULT); - int should_rebuild = (attr_chg_count > 1) || to == ATTR_DEFAULT; + int should_rebuild = (attr_chg_count > 1) || to == A_DEFAULT; if (should_rebuild) { vui_outs(CSI "0"); @@ -433,9 +432,7 @@ static void attr_chg(VuiAttr *ptr, VuiAttr to) { if (to & A_UNDERSCORE) vui_outs(";4"); if (to & A_BLINK) vui_outs(";5"); if (to & A_REVERSE) vui_outs(";7"); - from = ATTR_DEFAULT; - assert(ATTR_FG(from) == FG_WHITE); - assert(ATTR_BG(from) == BG_BLACK); + from = A_DEFAULT; } else { int sep = 0; vui_outs(CSI); @@ -472,17 +469,17 @@ chg_colors:; if (chg_attr) vui_outc(';'); else vui_outs(CSI); if (chg_fg) { - vui_outc(t_fg > 7 ? '9' : '3'); - vui_outc((t_fg & 7) + '0'); + vui_outc(t_fg > 9 ? '9' : '3'); + vui_outc((t_fg > 9 ? t_fg - 9 : t_fg) + '0'); } if (chg_bg) { if (chg_fg) vui_outc(';'); - if (t_bg > 7) { + if (t_bg > 9) { vui_outs("10"); } else { vui_outc('4'); } - vui_outc((t_bg & 7) + '0'); + vui_outc((t_bg > 9 ? t_bg - 9 : t_bg) + '0'); } } @@ -492,19 +489,19 @@ chg_colors:; void vui_scroll_buf(VuiBuffer *b, int dx, int dy); -static VuiAttr attr_last = ATTR_DEFAULT; +static VuiAttr attr_last = A_DEFAULT; static unsigned cur_x = 0; static unsigned cur_y = 0; static void emit_scroll_x(u32 y) { if (win.scroll_x < 0) { /* delete chars at start of line */ - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%dP", -win.scroll_x); } else if (win.scroll_x > 0) { /* insert spaces at start of line */ - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%d@", win.scroll_x); } @@ -516,13 +513,13 @@ static void emit_scroll_y(void) { if (win.scroll_y < 0) { /* delete lines at top */ curs_move(&cur_x, &cur_y, 0, 0); - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); if (win.scroll_y == -1) vui_outs(CSI "M"); else vui_outf(CSI "%dM", -win.scroll_y); } else if (win.scroll_y > 0) { /* insert blank lines at top */ curs_move(&cur_x, &cur_y, 0, 0); - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); if (win.scroll_y == 1) vui_outs(CSI "L"); else vui_outf(CSI "%dL", win.scroll_y); } @@ -534,7 +531,7 @@ void vui_blit(void) { if (win.redraw_all) { vui_outs(CSI "H" CSI "2J" CSI "0m"); - attr_last = ATTR_DEFAULT; + attr_last = A_DEFAULT; unsigned max = COLS * LINES; for (unsigned i = 0; i < max; i++) { attr_chg(&attr_last, front->attr[i]); @@ -593,7 +590,7 @@ void vui_chra(int x, int y, VuiChar c, VuiAttr a) { } void vui_chr(int x, int y, VuiChar c) { - vui_chra(x, y, c, ATTR_DEFAULT); + vui_chra(x, y, c, A_DEFAULT); } static void truncate_span(int *x, unsigned *nptr) { @@ -628,7 +625,7 @@ u32 vui_putsna(int x, int y, const char *s, unsigned srcn, VuiAttr a) { } u32 vui_putsn(int x, int y, const char *s, unsigned n) { - return vui_putsna(x, y, s, n, ATTR_DEFAULT); + return vui_putsna(x, y, s, n, A_DEFAULT); } u32 vui_putsa(int x, int y, const char *s, VuiAttr a) { @@ -666,7 +663,7 @@ int vui_aprintf(int x, int y, VuiAttr a, const char *fmt, ...) { int vui_printf(int x, int y, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - int r = vui_avprintf(x, y, ATTR_DEFAULT, fmt, ap); + int r = vui_avprintf(x, y, A_DEFAULT, fmt, ap); va_end(ap); return r; } -- cgit v1.2.3