summaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
commitbdaedce69b17b654bd0060579dd9b9ff120009b5 (patch)
tree0e9cd8597652263a96c48ba678fb0b66e1fc131b /src/text.c
parentba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff)
parentdcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff)
Merge branch 'wt/rename' into api-hardening
# Conflicts: # README.md
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c184
1 files changed, 92 insertions, 92 deletions
diff --git a/src/text.c b/src/text.c
index 17f3f4f..ae78722 100644
--- a/src/text.c
+++ b/src/text.c
@@ -12,7 +12,7 @@
#include <stdio.h>
#include <string.h>
-static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16_t flags)
+static inline void emit_codepoint(struct wsap_vtcore *t, uint32_t cp, int klass, uint16_t flags)
{
static const uint32_t dec_graphics[] = {
0x00a0,
@@ -28,7 +28,7 @@ static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16
char ch = c1_map[cp - 0x80];
if (ch) {
t->state = ST_ESC;
- term_escape_byte(t, (unsigned char)ch);
+ wsap_vtcore_escape_byte(t, (unsigned char)ch);
}
return;
}
@@ -39,38 +39,38 @@ static inline void emit_codepoint(struct term *t, uint32_t cp, int klass, uint16
sc_print_cell(t, cp, klass, flags);
}
-static inline void emit_decoded(struct term *t, uint32_t cp, uint16_t flags)
+static inline void emit_decoded(struct wsap_vtcore *t, uint32_t cp, uint16_t flags)
{
- int klass = term_text_class(cp);
- if (!term_sc_extend_cluster(t, cp, klass))
+ int klass = wsap_vtcore_text_class(cp);
+ if (!wsap_vtcore_sc_extend_cluster(t, cp, klass))
emit_codepoint(t, cp, klass, flags);
}
/* A byte that cannot continue a UTF-8 sequence ends it: the unfinished
* sequence prints U+FFFD (Unicode 3.9, maximal subparts). */
-void term_text_utf8_interrupt(struct term *t)
+void wsap_vtcore_text_utf8_interrupt(struct wsap_vtcore *t)
{
- if (TERM_EXPECT(t->utf8_state == TERM_UTF8_ACCEPT, 1))
+ if (WSAP_VTCORE_EXPECT(t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT, 1))
return;
- t->utf8_state = TERM_UTF8_ACCEPT;
- emit_decoded(t, 0xFFFD, term_current_flags(t));
+ t->utf8_state = WSAP_VTCORE_UTF8_ACCEPT;
+ emit_decoded(t, 0xFFFD, wsap_vtcore_current_flags(t));
}
-void term_text_ground(struct term *t, unsigned char ch)
+void wsap_vtcore_text_ground(struct wsap_vtcore *t, unsigned char ch)
{
- if (ch >= 0x20 && ch < 0x7f && t->utf8_state == TERM_UTF8_ACCEPT) {
- emit_codepoint(t, ch, 1, term_current_flags(t));
+ if (ch >= 0x20 && ch < 0x7f && t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT) {
+ emit_codepoint(t, ch, 1, wsap_vtcore_current_flags(t));
return;
}
if (ch < 0x20 || ch == 0x7f)
- term_text_utf8_interrupt(t);
+ wsap_vtcore_text_utf8_interrupt(t);
- if (TERM_EXPECT(ch == 0x1b, 0)) {
- term_escape_begin(t);
+ if (WSAP_VTCORE_EXPECT(ch == 0x1b, 0)) {
+ wsap_vtcore_escape_begin(t);
} else if (ch == '\n' || ch == 0x0b || ch == 0x0c) {
/* VT and FF act as LF (xterm). */
- if (term_lnm(t)) sc_cr(t);
+ if (wsap_vtcore_lnm(t)) sc_cr(t);
sc_linefeed(t, 1);
} else if (ch == '\r') {
sc_cr(t);
@@ -78,9 +78,9 @@ void term_text_ground(struct term *t, unsigned char ch)
t->pending_wrap = false;
if (t->cursor_x > 0)
t->cursor_x--;
- term_row(t, t->cursor_y)->version++;
+ wsap_vtcore_row(t, t->cursor_y)->version++;
} else if (ch == '\t') {
- term_sc_tab(t, 1);
+ wsap_vtcore_sc_tab(t, 1);
} else if (ch == 0x07) {
if (t->cb.bell)
t->cb.bell(t->cb.ud);
@@ -92,55 +92,55 @@ void term_text_ground(struct term *t, unsigned char ch)
t->graphics = t->charsets[0] == '0';
} else if (ch >= 0x20 && ch != 0x7f) {
uint32_t before = t->utf8_state;
- uint32_t st = term_utf8_decode(&t->utf8_state, &t->utf8_codep, ch);
- if (st == TERM_UTF8_ACCEPT) {
- emit_decoded(t, t->utf8_codep, term_current_flags(t));
- } else if (st == TERM_UTF8_REJECT) {
- t->utf8_state = TERM_UTF8_ACCEPT;
- emit_decoded(t, 0xFFFD, term_current_flags(t));
+ uint32_t st = wsap_vtcore_utf8_decode(&t->utf8_state, &t->utf8_codep, ch);
+ if (st == WSAP_VTCORE_UTF8_ACCEPT) {
+ emit_decoded(t, t->utf8_codep, wsap_vtcore_current_flags(t));
+ } else if (st == WSAP_VTCORE_UTF8_REJECT) {
+ t->utf8_state = WSAP_VTCORE_UTF8_ACCEPT;
+ emit_decoded(t, 0xFFFD, wsap_vtcore_current_flags(t));
/* The byte that ended an unfinished sequence starts anew. */
- if (before != TERM_UTF8_ACCEPT)
- term_text_ground(t, ch);
+ if (before != WSAP_VTCORE_UTF8_ACCEPT)
+ wsap_vtcore_text_ground(t, ch);
}
}
}
-static inline bool can_stream_bottom(const struct term *t)
+static inline bool can_stream_bottom(const struct wsap_vtcore *t)
{
return t->state == ST_GROUND && !t->graphics && !t->insert_mode && t->autowrap &&
!t->lr_margin_mode &&
- t->utf8_state == TERM_UTF8_ACCEPT && !t->inverse &&
+ t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && !t->inverse &&
t->scroll_top == 0 && t->scroll_bottom == t->rows - 1 &&
t->cursor_y == t->rows - 1 &&
!t->alternate && t->sb_capacity > 0 &&
using_default_colors(t);
}
-static inline bool try_text_run(struct term *t, const char *buf, size_t len,
+static inline bool try_text_run(struct wsap_vtcore *t, const char *buf, size_t len,
size_t *idx)
{
size_t i = *idx;
if (t->pending_wrap || i + 4 > len ||
((unsigned char)buf[i] >= 0x80 &&
((unsigned char)buf[i] < 0xc2 || (unsigned char)buf[i] > 0xf4)) ||
- t->last_char == 0x200D || term_grapheme_is_handle(t->last_char))
+ t->last_char == 0x200D || wsap_vtcore_grapheme_is_handle(t->last_char))
return false;
if (t->cursor_x != 0 &&
- t->cursor_x != term_row(t, t->cursor_y)->len)
+ t->cursor_x != wsap_vtcore_row(t, t->cursor_y)->len)
return false;
if ((unsigned char)buf[i] >= 0x80) {
uint32_t cp;
- int bytes = term_utf8_decode_one(buf + i, len - i, &cp);
- if (!bytes || term_text_class(cp) <= 0)
+ int bytes = wsap_vtcore_utf8_decode_one(buf + i, len - i, &cp);
+ if (!bytes || wsap_vtcore_text_class(cp) <= 0)
return false;
}
- struct text_pen pen = term_text_pen(t);
+ struct text_pen pen = wsap_vtcore_text_pen(t);
bool wrote = false;
do {
struct srow *text = t->insert_mode || t->lr_margin_mode ? NULL : text_append_row(t);
if (text) {
int x = t->cursor_x, avail = t->cols - x;
- struct text_run_bytes r = term_text_run_bytes(text->text.text + text->text.text_len,
+ struct text_run_bytes r = wsap_vtcore_text_run_bytes(text->text.text + text->text.text_len,
buf + i, (int)(len - i), avail,
t->last_char, &t->text_width);
if (!r.bytes)
@@ -156,7 +156,7 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len,
struct span span = sc_span_begin(t, t->cols);
if (span.avail < 2)
break;
- struct text_run_result r = term_text_run(span.cells, buf + i, (int)(len - i),
+ struct text_run_result r = wsap_vtcore_text_run(span.cells, buf + i, (int)(len - i),
span.avail, pen.fg, pen.bg, pen.sl, t->last_char,
&t->text_width);
if (!r.bytes)
@@ -175,45 +175,45 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len,
newline = true;
}
} else if (i < len && buf[i] == '\n') {
- if (term_lnm(t)) sc_cr(t);
+ if (wsap_vtcore_lnm(t)) sc_cr(t);
sc_linefeed(t, 1);
i++;
newline = true;
}
if (!newline || i + 4 > len || t->pending_wrap ||
- t->last_char == 0x200D || term_grapheme_is_handle(t->last_char) ||
+ t->last_char == 0x200D || wsap_vtcore_grapheme_is_handle(t->last_char) ||
(t->cursor_x != 0 &&
- t->cursor_x != term_row(t, t->cursor_y)->len))
+ t->cursor_x != wsap_vtcore_row(t, t->cursor_y)->len))
break;
} while (true);
if (wrote) *idx = i - 1;
return wrote;
}
-/* The feed flags this build knows. term_feed() rejects any other bit. */
-#define TERM_FEED_KNOWN TERM_FEED_ONLCR
+/* The feed flags this build knows. wsap_vtcore_feed() rejects any other bit. */
+#define WSAP_VTCORE_FEED_KNOWN WSAP_VTCORE_FEED_ONLCR
-static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigned flags)
+static void wsap_vtcore_feed_inner(struct wsap_vtcore *t, const char *buf, size_t len, unsigned flags)
{
- t->transport_newline = (flags & TERM_FEED_ONLCR) != 0;
- uint16_t cur_flags = term_current_flags(t);
+ t->transport_newline = (flags & WSAP_VTCORE_FEED_ONLCR) != 0;
+ uint16_t cur_flags = wsap_vtcore_current_flags(t);
for (size_t i = 0; i < len; i++) {
while (t->state != ST_GROUND) {
if (t->state == ST_CSI)
- i += term_escape_csi(t, buf + i, len - i);
+ i += wsap_vtcore_escape_csi(t, buf + i, len - i);
else if (t->state == ST_OSC || t->state == ST_DCS || t->state == ST_IGNORE)
- i += term_escape_str(t, buf + i, len - i);
+ i += wsap_vtcore_escape_str(t, buf + i, len - i);
else
- term_escape_byte(t, (unsigned char)buf[i++]);
- cur_flags = term_current_flags(t);
+ wsap_vtcore_escape_byte(t, (unsigned char)buf[i++]);
+ cur_flags = wsap_vtcore_current_flags(t);
if (i == len) return;
}
unsigned char ch = (unsigned char)buf[i];
- if (TERM_EXPECT(ch >= 0x20 && ch < 0x7f && !t->insert_mode && !t->lr_margin_mode &&
+ if (WSAP_VTCORE_EXPECT(ch >= 0x20 && ch < 0x7f && !t->insert_mode && !t->lr_margin_mode &&
t->state == ST_GROUND && !t->graphics &&
- t->utf8_state == TERM_UTF8_ACCEPT, 1)) {
+ t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT, 1)) {
int avail = t->pending_wrap ? t->cols : t->cols - t->cursor_x;
int rem = (int)(len - i);
if (rem > avail) rem = avail;
@@ -221,14 +221,14 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
if (rem > 1 && (unsigned char)buf[i + 1] >= 0x20 &&
(unsigned char)buf[i + 1] < 0x7f)
run += scan_ascii_run(buf + i + 1, rem - 1);
- if (TERM_EXPECT(can_stream_bottom(t), 1) &&
+ if (WSAP_VTCORE_EXPECT(can_stream_bottom(t), 1) &&
(run == t->cols ||
(i + (size_t)run < len &&
(buf[i + run] == '\r' || buf[i + run] == '\n')))) {
- struct srow *row = term_row(t, t->cursor_y);
+ struct srow *row = wsap_vtcore_row(t, t->cursor_y);
if (t->pending_wrap ||
(t->cursor_x == 0 && row && row->len == 0)) {
- size_t done = term_sc_bulk_ascii_lines(t, buf + i, len - i);
+ size_t done = wsap_vtcore_sc_bulk_ascii_lines(t, buf + i, len - i);
if (done > 0) {
i += done - 1;
continue;
@@ -240,8 +240,8 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
(unsigned char)buf[i + 1] <= 0xf4 &&
(i + 2 == len || ((unsigned char)buf[i + 2] & 0xc0) == 0x80)) {
uint32_t next_cp;
- if (term_utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) &&
- term_text_class(next_cp) > 0 &&
+ if (wsap_vtcore_utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) &&
+ wsap_vtcore_text_class(next_cp) > 0 &&
try_text_run(t, buf, len, &i))
continue;
}
@@ -250,8 +250,8 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
}
if (i + (size_t)run < len && (unsigned char)buf[i + run] >= 0x80) {
uint32_t next_cp;
- if (term_utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) &&
- term_text_class(next_cp) > 0 &&
+ if (wsap_vtcore_utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) &&
+ wsap_vtcore_text_class(next_cp) > 0 &&
try_text_run(t, buf, len, &i))
continue;
}
@@ -265,7 +265,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
i++;
}
} else if (i < len && buf[i] == '\n') {
- if (term_lnm(t)) sc_cr(t);
+ if (wsap_vtcore_lnm(t)) sc_cr(t);
sc_linefeed(t, 1);
i++;
}
@@ -273,38 +273,38 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
continue;
}
- if (TERM_EXPECT(ch >= 0x80, 1)) {
- if (TERM_EXPECT(t->state == ST_GROUND &&
- t->utf8_state == TERM_UTF8_ACCEPT && !t->graphics, 1)) {
+ if (WSAP_VTCORE_EXPECT(ch >= 0x80, 1)) {
+ if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND &&
+ t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && !t->graphics, 1)) {
if (ch >= 0xc2 && ch <= 0xf4 &&
(i + 1 == len || ((unsigned char)buf[i + 1] & 0xc0) == 0x80)) {
if (!t->insert_mode && !t->lr_margin_mode &&
try_text_run(t, buf, len, &i))
continue;
} else {
- if (TERM_EXPECT(t->last_char != 0x200D && !term_grapheme_is_handle(t->last_char), 1))
+ if (WSAP_VTCORE_EXPECT(t->last_char != 0x200D && !wsap_vtcore_grapheme_is_handle(t->last_char), 1))
sc_print_cell(t, 0xFFFD, 1, cur_flags);
else
emit_decoded(t, 0xFFFD, cur_flags);
continue;
}
uint32_t cp;
- int cp_len = term_utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp);
+ int cp_len = wsap_vtcore_utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp);
if (cp)
emit_decoded(t, cp, cur_flags);
i += (size_t)(cp_len - 1);
continue;
}
- if (TERM_EXPECT(t->state == ST_GROUND, 1))
- term_text_ground(t, ch);
+ if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND, 1))
+ wsap_vtcore_text_ground(t, ch);
else
- term_escape_byte(t, ch);
+ wsap_vtcore_escape_byte(t, ch);
continue;
}
- if (TERM_EXPECT(ch < 0x20 || ch == 0x7f, 0)) {
+ if (WSAP_VTCORE_EXPECT(ch < 0x20 || ch == 0x7f, 0)) {
if (t->state == ST_GROUND) {
- term_text_utf8_interrupt(t);
+ wsap_vtcore_text_utf8_interrupt(t);
if (ch == 0x7f || ((1u << ch) & 0x0800FF80u) == 0)
continue;
@@ -313,7 +313,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
case 0x0b:
case 0x0c: {
size_t end = i + 1 + scan_byte_run(buf + i + 1, len - i - 1, '\n');
- if (term_lnm(t)) sc_cr(t);
+ if (wsap_vtcore_lnm(t)) sc_cr(t);
sc_linefeed(t, end - i);
i = end - 1;
continue;
@@ -329,66 +329,66 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne
}
continue;
case 0x1b:
- if (t->utf8_state == TERM_UTF8_ACCEPT && i + 1 < len &&
+ if (t->utf8_state == WSAP_VTCORE_UTF8_ACCEPT && i + 1 < len &&
buf[i + 1] == '[' && !t->insert_mode &&
!t->lr_margin_mode && !t->graphics) {
- int fast = term_try_fast_csi(t, buf + i + 2, len - i - 2);
+ int fast = wsap_vtcore_try_fast_csi(t, buf + i + 2, len - i - 2);
if (fast > 0) {
- cur_flags = term_current_flags(t);
+ cur_flags = wsap_vtcore_current_flags(t);
i += 1 + (size_t)fast;
continue;
}
t->state = ST_CSI;
csi_parser_reset(&t->csi_parser);
- i += 1 + term_escape_csi(t, buf + i + 2, len - i - 2);
- cur_flags = term_current_flags(t);
+ i += 1 + wsap_vtcore_escape_csi(t, buf + i + 2, len - i - 2);
+ cur_flags = wsap_vtcore_current_flags(t);
continue;
}
- term_text_ground(t, ch);
- cur_flags = term_current_flags(t);
+ wsap_vtcore_text_ground(t, ch);
+ cur_flags = wsap_vtcore_current_flags(t);
continue;
default:
- term_text_ground(t, ch);
- cur_flags = term_current_flags(t);
+ wsap_vtcore_text_ground(t, ch);
+ cur_flags = wsap_vtcore_current_flags(t);
continue;
}
} else {
- term_escape_byte(t, ch);
- cur_flags = term_current_flags(t);
+ wsap_vtcore_escape_byte(t, ch);
+ cur_flags = wsap_vtcore_current_flags(t);
continue;
}
}
- if (TERM_EXPECT(t->state == ST_GROUND, 1))
- term_text_ground(t, ch);
+ if (WSAP_VTCORE_EXPECT(t->state == ST_GROUND, 1))
+ wsap_vtcore_text_ground(t, ch);
else
- term_escape_byte(t, ch);
- cur_flags = term_current_flags(t);
+ wsap_vtcore_escape_byte(t, ch);
+ cur_flags = wsap_vtcore_current_flags(t);
}
}
-bool term_feed(struct term *t, const char *buf, size_t len, unsigned flags)
+bool wsap_vtcore_feed(struct wsap_vtcore *t, const char *buf, size_t len, unsigned flags)
{
- if (!t || (!buf && len > 0) || (flags & ~TERM_FEED_KNOWN))
+ if (!t || (!buf && len > 0) || (flags & ~WSAP_VTCORE_FEED_KNOWN))
return false;
if (len == 0)
return true;
- term_write_begin(t);
- term_feed_inner(t, buf, len, flags);
- term_write_end(t);
+ wsap_vtcore_write_begin(t);
+ wsap_vtcore_feed_inner(t, buf, len, flags);
+ wsap_vtcore_write_end(t);
return true;
}
-void term_text_repeat(struct term *t, int count)
+void wsap_vtcore_text_repeat(struct wsap_vtcore *t, int count)
{
int screen = t->cols * t->rows;
if (count > screen) count = screen;
if (count <= 0 || !t->last_char)
return;
if (count == 1) {
- term_sc_print_glyph(t, t->last_char, -1, term_current_flags(t));
+ wsap_vtcore_sc_print_glyph(t, t->last_char, -1, wsap_vtcore_current_flags(t));
return;
}
for (int j = 0; j < count && t->last_char; j++)
- term_sc_print_glyph(t, t->last_char, -1, term_current_flags(t));
+ wsap_vtcore_sc_print_glyph(t, t->last_char, -1, wsap_vtcore_current_flags(t));
}