summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2025-11-06 21:31:59 -0500
committerWormHeamer2025-11-06 21:31:59 -0500
commit7d33e01cedc44335cbf7243005dbfdc656603c4b (patch)
tree6f86b195bc4e03ca0667cc46ff45b682f8cbf2ea /main.c
parente1d5fc63cdf1b1fb0c0f68ca08ba1e71a2a466b6 (diff)
guhyuck
Diffstat (limited to 'main.c')
-rw-r--r--main.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/main.c b/main.c
index f4d4ac4..b3503b8 100644
--- a/main.c
+++ b/main.c
@@ -463,8 +463,6 @@ 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 != 0);
if (!chg_attr) goto chg_colors;
@@ -486,8 +484,8 @@ 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 {
+ int sep = 0;
vui_outs(CSI);
if ((to ^ from) & A_BOLD) {
if (to & A_BOLD) M("1");
@@ -677,31 +675,43 @@ void vui_chr(int x, int y, VuiChar c) {
vui_chra(x, y, c, ATTR_DEFAULT);
}
+/*
static inline u32 utf8_next(u32 *p, const char *s, u32 n) {
u32 i = *p;
u8 c = s[i++];
usize bits = stdc_leading_ones(c);
- if (!bits) {
- *p = i;
- return c;
- }
ASSUME(bits < 5);
u32 cp = c & ((1 << (7-bits)) - 1);
- while (--bits) {
+ while (bits-- > 1) {
c = s[i++];
cp = (cp << 6) | (c & 0x3F);
}
*p = i;
return cp;
}
+*/
+
+static inline const char *utf8_next(u32 *out, const char *src) {
+ u8 c = *src++;
+ usize bits = stdc_leading_ones(c);
+ ASSUME(bits < 5);
+ u32 cp = c & (-1 >> bits);
+ while (bits-- > 1) {
+ c = *src++;
+ cp = (cp << 6) | (c & 0x3F);
+ }
+ *out = cp;
+ return src;
+}
+
+void utf8_decode(uint32_t *dst, const char *src, unsigned n) {
+ const char *end = src + n;
+ while (src < end) src = utf8_next(dst++, src);
+}
unsigned vui_putsna(int x, int y, const char *s, unsigned n, VuiAttr a) {
if (n > COLS - x) n = COLS - x;
- VuiChar *pc = &CHR(x, y);
- for (unsigned i = 0; i < n;) {
- u32 c = utf8_next(&i, s, n);
- *pc++ = c;
- }
+ utf8_decode(&CHR(x, y), s, n);
for (uint16_t *pa = &ATTR(x, y); n--;) *pa++ = a;
return n;
}
@@ -724,12 +734,13 @@ int vui_avprintf(int x, int y, VuiAttr a, const char *fmt, va_list ap) {
int n = vsnprintf(NULL, 0, fmt, ap);
if (x < 0) x = COLS + x - (n - 1);
if (y < 0) y = LINES + y;
- if (x >= COLS || y >= LINES) return n;
- if (n > 0) {
+ if (x + n > COLS) n = COLS - x;
+ if (x < COLS && y < LINES && n > 0) {
char buf[n + 1];
vsnprintf(buf, n + 1, fmt, ap2);
vui_putsna(x, y, buf, n, a);
}
+ va_end(ap2);
return n;
}
@@ -951,7 +962,7 @@ int main(int argc, const char **argv) {
return 0;
*/
- vui_curs_vis(0);
+ vui_curs_vis(1);
vui_win.redraw_fn = draw;
int x = 0, y = 0;
@@ -990,8 +1001,8 @@ int main(int argc, const char **argv) {
int okx = sx >= left - 5 && sx <= right + 5;
int oky = sy >= top - 2 && sy <= bottom + 2;
if (okx && oky) {
- ATTR(x, y) = FG_WHITE | BG_WHITE;
- } else if (oky && sx == right + 6 || okx && sy == bottom + 3 || sx == right + 6 && sy == bottom + 3) {
+ ATTR(x, y) = FG_BLACK | BG_WHITE;
+ } else if ((oky && sx == right + 6) || (okx && sy == bottom + 3) || (sx == right + 6 && sy == bottom + 3)) {
ATTR(x, y) = FG_BLACK | BG_BLACK;
} else {
ATTR(x, y) = FG_BLUE | BG_BLUE;
@@ -1000,7 +1011,7 @@ int main(int argc, const char **argv) {
}
}
- vui_chra(x, y, '_', FG_BLUE | BG_WHITE);
+ vui_curs_pos(x, y);
draw(NULL);
int animating = !!scroll_x || !!scroll_y;
@@ -1009,11 +1020,14 @@ int main(int argc, const char **argv) {
if (c == KEY_INVALID || c == KEY_ESC) goto done;
static unsigned i = 0;
i++;
- if (c > 0x1f && c < KEY_UTF8_MAX && x < right) {
- vui_chra(x++, y, c, FG_BLACK | BG_WHITE);
- } else if (c == KEY_RET) {
+ if (c == KEY_RET) {
x = left;
y += 2;
+ } else if (x < right) {
+ x += vui_aprintf(x, y, FG_BLACK | BG_WHITE, "%X ", c);
+ if (c < 0x20 || c > KEY_UTF8_MAX || c == 0x7f) c = 0xFFFD;
+ vui_chra(x, y, c, FG_BLACK | BG_WHITE);
+ x += 2;
}
/*