summaryrefslogtreecommitdiff
path: root/src/escape.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/escape.c
parentba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff)
parentdcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff)
Merge branch 'wt/rename' into api-hardening
# Conflicts: # README.md
Diffstat (limited to 'src/escape.c')
-rw-r--r--src/escape.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/src/escape.c b/src/escape.c
index dceb7a6..d5f61eb 100644
--- a/src/escape.c
+++ b/src/escape.c
@@ -11,27 +11,27 @@
#include <string.h>
#include <stdio.h>
-static int sgr_color_param(const struct term *t, char *buf, size_t sz, int base, uint32_t c)
+static int sgr_color_param(const struct wsap_vtcore *t, char *buf, size_t sz, int base, uint32_t c)
{
- if (term_color_is_slot(c) && (c & 0x1FFu) < 256) {
+ if (wsap_vtcore_color_is_slot(c) && (c & 0x1FFu) < 256) {
int i = (int)(c & 0xFFu);
/* The underline color has no short form. */
if (i < 16 && base != 50)
return snprintf(buf, sz, ";%d", i < 8 ? base + i : base + 60 + i - 8);
return snprintf(buf, sz, ";%d:5:%d", base + 8, i);
}
- if (term_color_is_slot(c))
- c = t->palette.colors[c & TERM_COLOR_SLOT_INDEX];
+ if (wsap_vtcore_color_is_slot(c))
+ c = t->palette.colors[c & WSAP_VTCORE_COLOR_SLOT_INDEX];
return snprintf(buf, sz, ";%d:2:%d:%d:%d", base + 8,
(int)((c >> 16) & 0xff), (int)((c >> 8) & 0xff), (int)(c & 0xff));
}
-static int sgr_serialize(const struct term *t, char *buf, size_t sz)
+static int sgr_serialize(const struct wsap_vtcore *t, char *buf, size_t sz)
{
int n = 0;
if (!(t->bold || t->faint || t->italic || t->underline || t->strike ||
- t->overline || t->inverse || t->cur_fg != TERM_COLOR_FG ||
- t->cur_bg != TERM_COLOR_BG || t->cur_ul))
+ t->overline || t->inverse || t->cur_fg != WSAP_VTCORE_COLOR_FG ||
+ t->cur_bg != WSAP_VTCORE_COLOR_BG || t->cur_ul))
return 0;
#define SGR_ADD(expr) \
do { \
@@ -47,8 +47,8 @@ static int sgr_serialize(const struct term *t, char *buf, size_t sz)
if (t->inverse) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";7"));
if (t->strike) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";9"));
if (t->overline) SGR_ADD(snprintf(buf + n, sz - (size_t)n, ";53"));
- if (t->cur_fg != TERM_COLOR_FG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 30, t->cur_fg));
- if (t->cur_bg != TERM_COLOR_BG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 40, t->cur_bg));
+ if (t->cur_fg != WSAP_VTCORE_COLOR_FG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 30, t->cur_fg));
+ if (t->cur_bg != WSAP_VTCORE_COLOR_BG) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 40, t->cur_bg));
if (t->cur_ul) SGR_ADD(sgr_color_param(t, buf + n, sz - (size_t)n, 50, t->cur_ul));
#undef SGR_ADD
return n;
@@ -105,7 +105,7 @@ static int tcap_cmp(const void *k, const void *e)
return strcmp(key, elem->name);
}
-static const char *term_tcap(const struct term *t, const char *name)
+static const char *wsap_vtcore_tcap(const struct wsap_vtcore *t, const char *name)
{
static const struct tcap_entry caps[] = {
{ "Co", "16777216" }, { "RGB", "8/8/8" },
@@ -193,7 +193,7 @@ static void resp_put(struct resp_buf *r, const char *s, size_t n)
if (r->failed)
return;
if (r->len + n + 1 > r->cap) {
- size_t cap = term_grow_cap(r->cap ? r->cap : 256, r->len + n + 1);
+ size_t cap = wsap_vtcore_grow_cap(r->cap ? r->cap : 256, r->len + n + 1);
char *p = realloc(r->s, cap);
if (!p) {
r->failed = true;
@@ -207,7 +207,7 @@ static void resp_put(struct resp_buf *r, const char *s, size_t n)
r->s[r->len] = '\0';
}
-static void dcs_xtgettcap(struct term *t, const char *buf, int len)
+static void dcs_xtgettcap(struct wsap_vtcore *t, const char *buf, int len)
{
static const char hex[] = "0123456789abcdef";
struct resp_buf r = {0};
@@ -226,7 +226,7 @@ static void dcs_xtgettcap(struct term *t, const char *buf, int len)
if (n < 0)
break;
name[n] = 0;
- const char *cap = term_tcap(t, name);
+ const char *cap = wsap_vtcore_tcap(t, name);
if (first && r.s) { r.s[2] = cap ? '1' : '0'; first = false; }
resp_put(&r, buf + i, (size_t)span);
if (!cap) break;
@@ -266,7 +266,7 @@ static int dcs_param_chr(const char **p, const char *end)
return v;
}
-static void restore_deccir(struct term *t, const char *p, const char *end)
+static void restore_deccir(struct wsap_vtcore *t, const char *p, const char *end)
{
int row = dcs_param_int(&p, end);
if (row <= 0 || row > t->rows) return;
@@ -300,9 +300,9 @@ static void restore_deccir(struct term *t, const char *p, const char *end)
t->graphics = t->charsets[t->charset_active] == '0';
}
-static void restore_dectabsr(struct term *t, const char *p, const char *end)
+static void restore_dectabsr(struct wsap_vtcore *t, const char *p, const char *end)
{
- term_tabs_clear(t);
+ wsap_vtcore_tabs_clear(t);
t->custom_tabs = true;
int stop = 0, any = 0;
for (; p < end; p++) {
@@ -319,18 +319,18 @@ static void restore_dectabsr(struct term *t, const char *p, const char *end)
if (any && --stop >= 0 && stop < t->tabs_cap) t->tabs[stop] = 1;
}
-/* Grows the DCS string to hold extra more bytes, up to TERM_OSC_MAX.
+/* Grows the DCS string to hold extra more bytes, up to WSAP_VTCORE_OSC_MAX.
* False when nothing more fits. */
-static bool dcs_reserve(struct term *t, size_t extra)
+static bool dcs_reserve(struct wsap_vtcore *t, size_t extra)
{
size_t need = (size_t)t->dcs_len + extra;
if (need <= t->dcs_cap)
return true;
- if (t->dcs_cap >= TERM_OSC_MAX)
+ if (t->dcs_cap >= WSAP_VTCORE_OSC_MAX)
return false;
- size_t cap = term_grow_cap(t->dcs_cap ? t->dcs_cap : 256, need);
- if (cap > TERM_OSC_MAX)
- cap = TERM_OSC_MAX;
+ size_t cap = wsap_vtcore_grow_cap(t->dcs_cap ? t->dcs_cap : 256, need);
+ if (cap > WSAP_VTCORE_OSC_MAX)
+ cap = WSAP_VTCORE_OSC_MAX;
char *p = realloc(t->dcs_buf, cap);
if (!p)
return false;
@@ -339,9 +339,9 @@ static bool dcs_reserve(struct term *t, size_t extra)
return need <= cap;
}
-static void dcs_dispatch(struct term *t)
+static void dcs_dispatch(struct wsap_vtcore *t)
{
- if (term_str_was_truncated(t))
+ if (wsap_vtcore_str_was_truncated(t))
return;
const char *buf = t->dcs_buf;
int len = t->dcs_len;
@@ -370,8 +370,8 @@ static void dcs_dispatch(struct term *t)
const char *spec = buf + 2;
int slen = len - 2, p;
if (slen == 2 && spec[0] == ' ' && spec[1] == 'q') {
- int shape = t->cursor_style == TERM_CURSOR_BLOCK ? (t->cursor_blink ? 1 : 2)
- : t->cursor_style == TERM_CURSOR_UNDERLINE ? (t->cursor_blink ? 3 : 4)
+ int shape = t->cursor_style == WSAP_VTCORE_CURSOR_BLOCK ? (t->cursor_blink ? 1 : 2)
+ : t->cursor_style == WSAP_VTCORE_CURSOR_UNDERLINE ? (t->cursor_blink ? 3 : 4)
: (t->cursor_blink ? 5 : 6);
p = snprintf(resp, sizeof(resp), "\033P1$r%d q\033\\", shape);
} else if (slen == 1 && spec[0] == 'm') {
@@ -421,7 +421,7 @@ static void dcs_dispatch(struct term *t)
}
}
-static void soft_reset(struct term *t)
+static void soft_reset(struct wsap_vtcore *t)
{
t->application_cursor = t->application_keypad = t->backarrow_sends_bs = false;
t->insert_mode = t->origin_mode = t->reverse_video = t->lnm = false;
@@ -439,14 +439,14 @@ static void soft_reset(struct term *t)
reset_sgr(t);
}
-static inline void sgr_set_slot(struct term *t, int code, uint32_t c)
+static inline void sgr_set_slot(struct wsap_vtcore *t, int code, uint32_t c)
{
if (code == 38) t->cur_fg = c;
else if (code == 48) t->cur_bg = c;
else t->cur_ul = c;
}
-static inline void handle_sgr(struct term *t, const struct csi *csi)
+static inline void handle_sgr(struct wsap_vtcore *t, const struct csi *csi)
{
if (csi->nparams == 0) {
reset_sgr(t);
@@ -456,20 +456,20 @@ static inline void handle_sgr(struct term *t, const struct csi *csi)
if (csi->nparams == 1 && !csi->subparams) {
int p = csi->params[0];
if (p == 0) { reset_sgr(t); return; }
- if ((unsigned)(p - 30) < 8) { t->cur_fg = term_color_index(p - 30); return; }
- if ((unsigned)(p - 40) < 8) { t->cur_bg = term_color_index(p - 40); return; }
- if ((unsigned)(p - 90) < 8) { t->cur_fg = term_color_index(p - 90 + 8); return; }
- if ((unsigned)(p - 100) < 8) { t->cur_bg = term_color_index(p - 100 + 8); return; }
+ if ((unsigned)(p - 30) < 8) { t->cur_fg = wsap_vtcore_color_index(p - 30); return; }
+ if ((unsigned)(p - 40) < 8) { t->cur_bg = wsap_vtcore_color_index(p - 40); return; }
+ if ((unsigned)(p - 90) < 8) { t->cur_fg = wsap_vtcore_color_index(p - 90 + 8); return; }
+ if ((unsigned)(p - 100) < 8) { t->cur_bg = wsap_vtcore_color_index(p - 100 + 8); return; }
if (p == 1) { t->bold = true; return; }
- if (p == 39) { t->cur_fg = TERM_COLOR_FG; return; }
- if (p == 49) { t->cur_bg = TERM_COLOR_BG; return; }
+ if (p == 39) { t->cur_fg = WSAP_VTCORE_COLOR_FG; return; }
+ if (p == 49) { t->cur_bg = WSAP_VTCORE_COLOR_BG; return; }
}
if (!csi->subparams) {
if (csi->nparams == 5 && csi->params[1] == 2 &&
(csi->params[0] == 38 || csi->params[0] == 48)) {
sgr_set_slot(t, csi->params[0],
- term_rgb(csi->params[2], csi->params[3], csi->params[4]));
+ wsap_vtcore_rgb(csi->params[2], csi->params[3], csi->params[4]));
return;
}
@@ -477,16 +477,16 @@ static inline void handle_sgr(struct term *t, const struct csi *csi)
(csi->params[0] == 38 || csi->params[0] == 48) &&
csi->params[5] == (csi->params[0] == 38 ? 48 : 38)) {
sgr_set_slot(t, csi->params[0],
- term_rgb(csi->params[2], csi->params[3], csi->params[4]));
+ wsap_vtcore_rgb(csi->params[2], csi->params[3], csi->params[4]));
sgr_set_slot(t, csi->params[5],
- term_rgb(csi->params[7], csi->params[8], csi->params[9]));
+ wsap_vtcore_rgb(csi->params[7], csi->params[8], csi->params[9]));
return;
}
if (csi->nparams == 3 && csi->params[1] == 5 &&
(csi->params[0] == 38 || csi->params[0] == 48) &&
(unsigned)csi->params[2] < 256) {
- sgr_set_slot(t, csi->params[0], term_color_index(csi->params[2]));
+ sgr_set_slot(t, csi->params[0], wsap_vtcore_color_index(csi->params[2]));
return;
}
@@ -494,13 +494,13 @@ static inline void handle_sgr(struct term *t, const struct csi *csi)
(csi->params[0] == 38 || csi->params[0] == 48) &&
csi->params[3] == (csi->params[0] == 38 ? 48 : 38) &&
(unsigned)csi->params[2] < 256 && (unsigned)csi->params[5] < 256) {
- sgr_set_slot(t, csi->params[0], term_color_index(csi->params[2]));
- sgr_set_slot(t, csi->params[3], term_color_index(csi->params[5]));
+ sgr_set_slot(t, csi->params[0], wsap_vtcore_color_index(csi->params[2]));
+ sgr_set_slot(t, csi->params[3], wsap_vtcore_color_index(csi->params[5]));
return;
}
}
- struct term_pen pen = {
+ struct wsap_vtcore_pen pen = {
.fg = t->cur_fg, .bg = t->cur_bg, .ul = t->cur_ul,
.underline = t->underline,
.bold = t->bold, .faint = t->faint, .italic = t->italic,
@@ -519,7 +519,7 @@ static inline void handle_sgr(struct term *t, const struct csi *csi)
t->inverse = pen.inverse;
}
-#define TERM_PRIV_MODE_FIELDS(X) \
+#define WSAP_VTCORE_PRIV_MODE_FIELDS(X) \
X(1, application_cursor) \
X(12, cursor_blink) \
X(25, cursor_visible) \
@@ -528,16 +528,16 @@ static inline void handle_sgr(struct term *t, const struct csi *csi)
X(2004, bracketed_paste) \
X(2026, synchronized_output)
-#define TERM_ANSI_MODE_FIELDS(X) \
+#define WSAP_VTCORE_ANSI_MODE_FIELDS(X) \
X(4, insert_mode) \
X(20, lnm)
-static int mode_get(const struct term *t, int mode, bool priv)
+static int mode_get(const struct wsap_vtcore *t, int mode, bool priv)
{
if (priv) {
switch (mode) {
#define MODE_FIELD_GET(n, f) case n: return t->f;
- TERM_PRIV_MODE_FIELDS(MODE_FIELD_GET)
+ WSAP_VTCORE_PRIV_MODE_FIELDS(MODE_FIELD_GET)
#undef MODE_FIELD_GET
case 5: return t->reverse_video;
case 6: return t->origin_mode;
@@ -552,30 +552,30 @@ static int mode_get(const struct term *t, int mode, bool priv)
}
switch (mode) {
#define MODE_FIELD_GET(n, f) case n: return t->f;
- TERM_ANSI_MODE_FIELDS(MODE_FIELD_GET)
+ WSAP_VTCORE_ANSI_MODE_FIELDS(MODE_FIELD_GET)
#undef MODE_FIELD_GET
}
return -1;
}
-static int cursor_top(const struct term *t) { return t->origin_mode ? t->scroll_top : 0; }
-static int cursor_bottom(const struct term *t) { return t->origin_mode ? t->scroll_bottom : t->rows - 1; }
-static int cursor_left(const struct term *t) { return t->origin_mode && t->lr_margin_mode ? t->left_margin : 0; }
-static int cursor_right(const struct term *t) { return t->origin_mode && t->lr_margin_mode ? t->right_margin : t->cols - 1; }
+static int cursor_top(const struct wsap_vtcore *t) { return t->origin_mode ? t->scroll_top : 0; }
+static int cursor_bottom(const struct wsap_vtcore *t) { return t->origin_mode ? t->scroll_bottom : t->rows - 1; }
+static int cursor_left(const struct wsap_vtcore *t) { return t->origin_mode && t->lr_margin_mode ? t->left_margin : 0; }
+static int cursor_right(const struct wsap_vtcore *t) { return t->origin_mode && t->lr_margin_mode ? t->right_margin : t->cols - 1; }
-static void mode_set(struct term *t, int mode, bool enabled, bool priv)
+static void mode_set(struct wsap_vtcore *t, int mode, bool enabled, bool priv)
{
if (!priv) {
switch (mode) {
#define MODE_FIELD_SET(n, f) case n: t->f = enabled; break;
- TERM_ANSI_MODE_FIELDS(MODE_FIELD_SET)
+ WSAP_VTCORE_ANSI_MODE_FIELDS(MODE_FIELD_SET)
#undef MODE_FIELD_SET
}
return;
}
switch (mode) {
#define MODE_FIELD_SET(n, f) case n: t->f = enabled; return;
- TERM_PRIV_MODE_FIELDS(MODE_FIELD_SET)
+ WSAP_VTCORE_PRIV_MODE_FIELDS(MODE_FIELD_SET)
#undef MODE_FIELD_SET
default: break;
}
@@ -591,10 +591,10 @@ static void mode_set(struct term *t, int mode, bool enabled, bool priv)
t->autowrap = enabled;
t->pending_wrap = false;
} else if (mode == 1048) {
- if (enabled) t->saved = term_cursor_save(t);
+ if (enabled) t->saved = wsap_vtcore_cursor_save(t);
else sc_restore_cursor(t, &t->saved);
} else if (mode == 47 || mode == 1047 || mode == 1049) {
- term_screen_set_alternate(t, enabled);
+ wsap_vtcore_screen_set_alternate(t, enabled);
} else if (mode_is_mouse(mode)) {
t->mouse_mode = enabled ? mode : 0;
} else if (mode == 69) {
@@ -608,7 +608,7 @@ static void mode_set(struct term *t, int mode, bool enabled, bool priv)
/* Vertical moves stop at a margin when they start inside the scroll
* region (xterm, DEC STD 070). */
-static inline void move_v(struct term *t, int n, bool col0)
+static inline void move_v(struct wsap_vtcore *t, int n, bool col0)
{
int top = t->cursor_y >= t->scroll_top ? t->scroll_top : 0;
int bottom = t->cursor_y <= t->scroll_bottom ? t->scroll_bottom : t->rows - 1;
@@ -616,7 +616,7 @@ static inline void move_v(struct term *t, int n, bool col0)
: (n < bottom - t->cursor_y ? t->cursor_y + n : bottom);
sc_move(t, col0 ? cursor_left(t) : t->cursor_x, y);
}
-static inline void move_h(struct term *t, int n, bool margin_aware)
+static inline void move_h(struct wsap_vtcore *t, int n, bool margin_aware)
{
int right = margin_aware ? cursor_right(t) : t->cols - 1;
int x = n < 0 ? (t->cursor_x >= -n ? t->cursor_x + n : 0)
@@ -624,15 +624,15 @@ static inline void move_h(struct term *t, int n, bool margin_aware)
sc_move(t, x, t->cursor_y);
}
-static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct csi *csi)
+static inline WSAP_VTCORE_ALWAYS_INLINE void dispatch_csi(struct wsap_vtcore *t, const struct csi *csi)
{
- if (TERM_EXPECT(csi->final == 'm', 1)) {
- if (TERM_EXPECT(!csi->prefix && !csi->intermediate, 1))
+ if (WSAP_VTCORE_EXPECT(csi->final == 'm', 1)) {
+ if (WSAP_VTCORE_EXPECT(!csi->prefix && !csi->intermediate, 1))
handle_sgr(t, csi);
return;
}
- if (TERM_EXPECT(csi->final == 'H' || csi->final == 'f', 0)) {
- if (TERM_EXPECT(!csi->prefix && !csi->intermediate && !csi->subparams, 1)) {
+ if (WSAP_VTCORE_EXPECT(csi->final == 'H' || csi->final == 'f', 0)) {
+ if (WSAP_VTCORE_EXPECT(!csi->prefix && !csi->intermediate && !csi->subparams, 1)) {
int64_t r = (int64_t)(csi->params[0] > 0 ? csi->params[0] - 1 : 0) + cursor_top(t);
if (r > cursor_bottom(t)) r = cursor_bottom(t);
int64_t c = (int64_t)(csi->nparams > 1 && csi->params[1] > 0 ? csi->params[1] - 1 : 0) + cursor_left(t);
@@ -668,7 +668,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
switch (csi->final) {
case 'r': {
if (csi->intermediate == '$') {
- term_sc_deccara(t, csi);
+ wsap_vtcore_sc_deccara(t, csi);
break;
}
if (csi->prefix || csi->intermediate) break;
@@ -684,7 +684,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
case 'L':
case 'M':
if (csi->prefix || t->cursor_y < t->scroll_top || t->cursor_y > t->scroll_bottom) break;
- term_screen_scroll_region(t, t->cursor_y, t->scroll_bottom,
+ wsap_vtcore_screen_scroll_region(t, t->cursor_y, t->scroll_bottom,
csi_count(csi), csi->final == 'L', false);
/* IL and DL move the cursor to the left margin (xterm). */
sc_move(t, t->lr_margin_mode ? t->left_margin : 0, t->cursor_y);
@@ -692,7 +692,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
case 'S':
case 'T':
if (csi->prefix || csi->nparams > 1) break;
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom,
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom,
csi_count(csi), csi->final == 'T', true);
break;
case 'd': {
@@ -702,7 +702,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
break;
}
case 'b':
- term_text_repeat(t, csi_count(csi));
+ wsap_vtcore_text_repeat(t, csi_count(csi));
break;
case 'A': move_v(t, -csi_count(csi), false); break;
case 'B': move_v(t, csi_count(csi), false); break;
@@ -727,25 +727,25 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
sc_move(t, t->origin_mode ? left : 0, cursor_top(t));
}
} else if (!csi->prefix) {
- t->saved = term_cursor_save(t);
+ t->saved = wsap_vtcore_cursor_save(t);
}
break;
case 'I':
case 'Z':
- term_sc_tab(t, csi->final == 'I' ? csi_count(csi) : -csi_count(csi));
+ wsap_vtcore_sc_tab(t, csi->final == 'I' ? csi_count(csi) : -csi_count(csi));
break;
case 'g':
if (csi->params[0] == 0) {
t->tabs[t->cursor_x] = 0;
t->custom_tabs = true;
} else if (csi->params[0] == 3) {
- term_tabs_clear(t);
+ wsap_vtcore_tabs_clear(t);
}
break;
case 'W':
if (csi->prefix == '?' && csi->params[0] == 5) {
- term_tabs_clear(t);
- term_tabs_default(t);
+ wsap_vtcore_tabs_clear(t);
+ wsap_vtcore_tabs_default(t);
}
break;
case 'n':
@@ -759,7 +759,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
}
break;
case 'J':
- term_screen_erase(t, csi->params[0]);
+ wsap_vtcore_screen_erase(t, csi->params[0]);
break;
case 'X': {
int n = csi_count(csi);
@@ -772,13 +772,13 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
t->decsace = (uint8_t)csi->params[0];
break;
case 'K':
- term_screen_erase_line(t, csi->params[0]);
+ wsap_vtcore_screen_erase_line(t, csi->params[0]);
break;
case 'P':
- term_screen_delete_chars(t, csi_count(csi));
+ wsap_vtcore_screen_delete_chars(t, csi_count(csi));
break;
case '@':
- term_screen_insert_chars(t, csi_count(csi));
+ wsap_vtcore_screen_insert_chars(t, csi_count(csi));
break;
case 'c': {
if (csi->prefix == '>')
@@ -838,7 +838,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
snprintf(resp, sizeof(resp), "\033P>|%s\033\\", t->name);
send_response(t, resp);
} else if (!csi->prefix && csi->intermediate == ' ') {
- term_sc_set_cursor_style(t, csi->nparams > 0 ? csi->params[0] : 0);
+ wsap_vtcore_sc_set_cursor_style(t, csi->nparams > 0 ? csi->params[0] : 0);
}
break;
}
@@ -861,7 +861,7 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
}
/* Formats one trace line and hands it to the host's trace callback. */
-static void esc_tracef(const struct term *t, const char *fmt, ...)
+static void esc_tracef(const struct wsap_vtcore *t, const char *fmt, ...)
{
char line[512];
va_list ap;
@@ -875,7 +875,7 @@ static void esc_tracef(const struct term *t, const char *fmt, ...)
#define ESC_TRACE(t, ...) \
do { if ((t)->cb.trace) esc_tracef((t), __VA_ARGS__); } while (0)
-static void dispatch_esc(struct term *t, unsigned char ch)
+static void dispatch_esc(struct wsap_vtcore *t, unsigned char ch)
{
t->state = ST_GROUND;
switch (ch) {
@@ -890,9 +890,9 @@ static void dispatch_esc(struct term *t, unsigned char ch)
t->custom_tabs = true;
break;
case 'c':
- if (t->alternate) term_screen_set_alternate(t, false);
+ if (t->alternate) wsap_vtcore_screen_set_alternate(t, false);
soft_reset(t);
- term_sc_reset(t);
+ wsap_vtcore_sc_reset(t);
break;
case '[':
ESC_TRACE(t, "ESC[ → ST_CSI");
@@ -939,12 +939,12 @@ static void dispatch_esc(struct term *t, unsigned char ch)
break;
case 'M':
if (t->cursor_y == t->scroll_top)
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, 1, true, false);
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, 1, true, false);
else
sc_move(t, t->cursor_x, t->cursor_y > 0 ? t->cursor_y - 1 : 0);
break;
case '7':
- t->saved = term_cursor_save(t);
+ t->saved = wsap_vtcore_cursor_save(t);
break;
case '8':
sc_restore_cursor(t, &t->saved);
@@ -954,7 +954,7 @@ static void dispatch_esc(struct term *t, unsigned char ch)
}
}
-void term_escape_byte(struct term *t, unsigned char ch)
+void wsap_vtcore_escape_byte(struct wsap_vtcore *t, unsigned char ch)
{
if (ch >= 0x80 && t->state != ST_OSC && t->state != ST_DCS &&
t->state != ST_IGNORE) {
@@ -962,7 +962,7 @@ void term_escape_byte(struct term *t, unsigned char ch)
t->osc_len = 0;
t->dcs_len = 0;
t->state = ST_GROUND;
- term_text_ground(t, ch);
+ wsap_vtcore_text_ground(t, ch);
return;
}
switch (t->state) {
@@ -970,7 +970,7 @@ void term_escape_byte(struct term *t, unsigned char ch)
ESC_TRACE(t, " ESC+0x%02x('%c')", ch, ch >= 0x20 && ch < 0x7f ? ch : '.');
if (ch < 0x20) {
t->state = ST_GROUND;
- term_text_ground(t, ch);
+ wsap_vtcore_text_ground(t, ch);
} else {
dispatch_esc(t, ch);
}
@@ -985,7 +985,7 @@ void term_escape_byte(struct term *t, unsigned char ch)
} else if (ch < 0x20) {
/* Other C0 controls run inside the sequence (ECMA-48 5.5,
* xterm). */
- term_text_ground(t, ch);
+ wsap_vtcore_text_ground(t, ch);
}
break;
case ST_CHARSET:
@@ -997,15 +997,15 @@ void term_escape_byte(struct term *t, unsigned char ch)
break;
case ST_DOCS:
if (ch != 'G' && ch != '@' && ch != '/')
- term_text_ground(t, '%');
+ wsap_vtcore_text_ground(t, '%');
t->state = ST_GROUND;
if (ch != 'G' && ch != '@' && ch != '/')
- term_text_ground(t, ch);
+ wsap_vtcore_text_ground(t, ch);
break;
case ST_DECALN:
t->state = ST_GROUND;
if (ch == '8')
- term_sc_decaln(t);
+ wsap_vtcore_sc_decaln(t);
break;
case ST_IGNORE:
if (ch == 0x07 || ch == 0x18 || ch == 0x1a)
@@ -1018,21 +1018,21 @@ void term_escape_byte(struct term *t, unsigned char ch)
t->state = ST_GROUND;
else {
t->state = ST_ESC;
- term_escape_byte(t, ch);
+ wsap_vtcore_escape_byte(t, ch);
}
break;
case ST_OSC:
if (ch == 0x07) {
- term_osc_finish(t);
+ wsap_vtcore_osc_finish(t);
t->state = ST_GROUND;
} else if (ch == 0x1b) {
t->state = ST_STR_ESC;
} else if (ch < 0x20) {
t->osc_len = 0;
t->state = ST_GROUND;
- term_text_ground(t, ch);
- } else if (term_osc_room(t) || term_osc_grow(t)) {
- *term_osc_tail(t) = (char)ch;
+ wsap_vtcore_text_ground(t, ch);
+ } else if (wsap_vtcore_osc_room(t) || wsap_vtcore_osc_grow(t)) {
+ *wsap_vtcore_osc_tail(t) = (char)ch;
t->osc_len++;
} else {
t->str_truncated = true;
@@ -1048,7 +1048,7 @@ void term_escape_byte(struct term *t, unsigned char ch)
} else if (ch < 0x20) {
t->dcs_len = 0;
t->state = ST_GROUND;
- term_text_ground(t, ch);
+ wsap_vtcore_text_ground(t, ch);
} else if (dcs_reserve(t, 1)) {
t->dcs_buf[t->dcs_len++] = (char)ch;
} else {
@@ -1063,18 +1063,18 @@ void term_escape_byte(struct term *t, unsigned char ch)
} else {
t->dcs_len = 0;
t->state = ST_ESC;
- term_escape_byte(t, ch);
+ wsap_vtcore_escape_byte(t, ch);
}
break;
case ST_STR_ESC:
if (ch == '\\') {
- term_osc_finish(t);
+ wsap_vtcore_osc_finish(t);
t->state = ST_GROUND;
} else {
t->osc_len = 0;
t->dcs_len = 0;
t->state = ST_ESC;
- term_escape_byte(t, ch);
+ wsap_vtcore_escape_byte(t, ch);
}
break;
default:
@@ -1082,24 +1082,24 @@ void term_escape_byte(struct term *t, unsigned char ch)
}
}
-size_t term_escape_str(struct term *t, const char *buf, size_t len)
+size_t wsap_vtcore_escape_str(struct wsap_vtcore *t, const char *buf, size_t len)
{
if (t->state == ST_IGNORE) {
size_t take = scan_printable_span(buf, len, 0x80);
if (take < len)
- term_escape_byte(t, (unsigned char)buf[take++]);
+ wsap_vtcore_escape_byte(t, (unsigned char)buf[take++]);
return take;
}
int is_osc = t->state == ST_OSC;
size_t take = scan_printable_span(buf, len, 0x80);
if (is_osc) {
- size_t room = term_osc_room(t);
- if (take > room && term_osc_grow(t))
- room = term_osc_room(t);
+ size_t room = wsap_vtcore_osc_room(t);
+ if (take > room && wsap_vtcore_osc_grow(t))
+ room = wsap_vtcore_osc_room(t);
if (room) {
if (take > room)
take = room;
- memcpy(term_osc_tail(t), buf, take);
+ memcpy(wsap_vtcore_osc_tail(t), buf, take);
t->osc_len += (int)take;
} else {
t->str_truncated = true;
@@ -1117,16 +1117,16 @@ size_t term_escape_str(struct term *t, const char *buf, size_t len)
}
}
if (take < len)
- term_escape_byte(t, (unsigned char)buf[take++]);
+ wsap_vtcore_escape_byte(t, (unsigned char)buf[take++]);
return take;
}
-size_t term_escape_csi(struct term *t, const char *buf, size_t len)
+size_t wsap_vtcore_escape_csi(struct wsap_vtcore *t, const char *buf, size_t len)
{
size_t consumed;
enum csi_result result = csi_read(&t->csi_parser, buf, len, &consumed);
if (result == CSI_CONTROL) {
- term_escape_byte(t, (unsigned char)buf[consumed++]);
+ wsap_vtcore_escape_byte(t, (unsigned char)buf[consumed++]);
} else if (result == CSI_DISPATCH || result == CSI_DISCARD) {
if (t->cb.trace) {
const struct csi *c = &t->csi_parser.csi;
@@ -1148,7 +1148,7 @@ size_t term_escape_csi(struct term *t, const char *buf, size_t len)
return consumed;
}
-void term_escape_begin(struct term *t)
+void wsap_vtcore_escape_begin(struct wsap_vtcore *t)
{
ESC_TRACE(t, "0x1b → ST_ESC");
t->state = ST_ESC;