commit e684149
uint
·
2026-05-13 20:43:30 +0000 UTC
parent c523129
add utf8 support, use term_write with libgrapheme
4 files changed,
+37,
-4
+2,
-4
1@@ -12,7 +12,6 @@
2 #include <unistd.h>
3
4 #include <RGFW.h>
5-#include <grapheme.h>
6 #include <schrift.h>
7
8 #include "draw.h"
9@@ -144,7 +143,7 @@ static void init(void)
10 /* TODO: paths */
11 if (font_load(&font, "./Xanh.ttf", 24.0) < 0)
12 die(1, "failed to load font");
13- font.aa = false;
14+ font.aa = true;
15 term_clear(&term, &car);
16 }
17
18@@ -162,8 +161,7 @@ static void ptyread(void)
19 if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
20 break;
21 if (n > 0) {
22- for (ssize_t i = 0; i < n; i++)
23- term_putc(&term, &car, (unsigned char)buf[i]);
24+ term_write(&term, &car, buf, n);
25 continue;
26 }
27
+12,
-0
1@@ -24,8 +24,10 @@ typedef struct {
2 Rune* runes;
3 uint32_t fg;
4 uint32_t bg;
5+
6 int cols;
7 int rows;
8+
9 int ptyfd;
10 pid_t ptypid;
11 } Term;
12@@ -55,5 +57,15 @@ void term_putc(Term* t, Caret* c, uint32_t cp);
13 */
14 void term_scroll(Term* t);
15
16+/**
17+ * @brief handle placing special and normal characters
18+ *
19+ * @param t terminal instance
20+ * @param c cursor instance
21+ * @param s string buffer to write
22+ * @param n length of string buffer
23+ */
24+void term_write(Term* t, Caret* c, const char* s, size_t n);
25+
26 #endif /* TERM_H */
27
+21,
-0
1@@ -1,6 +1,8 @@
2 #include <stdbool.h>
3 #include <string.h>
4
5+#include <grapheme.h>
6+
7 #include "term.h"
8
9 void term_clear(Term* t, Caret* c)
10@@ -77,3 +79,22 @@ void term_scroll(Term* t)
11 }
12 }
13
14+void term_write(Term* t, Caret* c, const char* s, size_t n)
15+{
16+ size_t off = 0;
17+
18+ while (off < n) {
19+ uint32_t cp;
20+ /* s+off: pointer to current position
21+ * n-off: remaining bytes
22+ */
23+ size_t len = grapheme_decode_utf8(s+off, n-off, &cp);
24+
25+ if (len ==0)
26+ break;
27+
28+ term_putc(t, c, cp);
29+ off += len;
30+ }
31+}
32+
+2,
-0
1@@ -0,0 +1,2 @@
2+echo "å∫ç∂´ƒ©˙ˆ∆˚¬µ˜øπœ®ß†¨√∑≈🇾Ω"
3+