summaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c282
1 files changed, 141 insertions, 141 deletions
diff --git a/src/core.c b/src/core.c
index dd6232a..a18f091 100644
--- a/src/core.c
+++ b/src/core.c
@@ -16,13 +16,13 @@ static uint16_t cluster_presentation(const uint32_t *cps, int len)
{
if (len <= 1)
return 0;
- bool pictographic = term_unicode_extended_pictographic(cps[0]);
+ bool pictographic = wsap_vtcore_unicode_extended_pictographic(cps[0]);
if (len == 2) {
uint32_t c1 = cps[1];
if (c1 == 0xFE0F) return CELL_EMOJI;
if (c1 == 0xFE0E) return CELL_TEXT;
- if (c1 == 0x20E3 || term_grapheme_regional_indicator(c1) ||
- (pictographic && (c1 == 0x200D || term_grapheme_emoji_modifier(c1) ||
+ if (c1 == 0x20E3 || wsap_vtcore_grapheme_regional_indicator(c1) ||
+ (pictographic && (c1 == 0x200D || wsap_vtcore_grapheme_emoji_modifier(c1) ||
(c1 >= 0xE0020 && c1 <= 0xE007F))))
return CELL_EMOJI;
return 0;
@@ -33,40 +33,40 @@ static uint16_t cluster_presentation(const uint32_t *cps, int len)
return CELL_EMOJI;
if (cps[i] == 0xFE0E)
return CELL_TEXT;
- if (cps[i] == 0x20E3 || term_grapheme_regional_indicator(cps[i]) ||
- (pictographic && (cps[i] == 0x200D || term_grapheme_emoji_modifier(cps[i]) ||
+ if (cps[i] == 0x20E3 || wsap_vtcore_grapheme_regional_indicator(cps[i]) ||
+ (pictographic && (cps[i] == 0x200D || wsap_vtcore_grapheme_emoji_modifier(cps[i]) ||
(cps[i] >= 0xE0020 && cps[i] <= 0xE007F))))
emoji = true;
}
return emoji ? CELL_EMOJI : 0;
}
-void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags)
+void wsap_vtcore_sc_print_glyph(struct wsap_vtcore *t, uint32_t cp, int width, uint16_t flags)
{
uint32_t base = cp;
- if (TERM_EXPECT(term_grapheme_is_handle(cp), 0)) {
- uint32_t cps[TERM_GRAPHEME_MAX_LEN];
- int len = term_gstore_expand(t->gstore, cp, cps, TERM_GRAPHEME_MAX_LEN);
+ if (WSAP_VTCORE_EXPECT(wsap_vtcore_grapheme_is_handle(cp), 0)) {
+ uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN];
+ int len = wsap_vtcore_gstore_expand(t->gstore, cp, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN);
base = cps[0];
flags = (flags & ~(CELL_EMOJI | CELL_TEXT)) | cluster_presentation(cps, len);
}
- if (TERM_EXPECT(width <= 0, 0))
- width = term_text_class(base);
+ if (WSAP_VTCORE_EXPECT(width <= 0, 0))
+ width = wsap_vtcore_text_class(base);
if (width == 2 || (flags & CELL_EMOJI))
width = 2;
else
width = 1;
- if (TERM_EXPECT(flags & CELL_TEXT, 0))
+ if (WSAP_VTCORE_EXPECT(flags & CELL_TEXT, 0))
width = 1;
- if (TERM_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode &&
+ if (WSAP_VTCORE_EXPECT(width == 1 && !t->pending_wrap && !t->insert_mode &&
!t->lr_margin_mode && t->cursor_x < t->cols, 1)) {
- struct srow *srow = term_row(t, t->cursor_y);
+ struct srow *srow = wsap_vtcore_row(t, t->cursor_y);
int cx = t->cursor_x;
int len = srow->len;
- if (TERM_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) {
+ if (WSAP_VTCORE_EXPECT(srow->kind == ROW_CELLS && cx <= len, 1)) {
struct cell *row = srow->cells;
- if (TERM_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) ||
+ if (WSAP_VTCORE_EXPECT(!((cx < len && (row[cx].flags & CELL_TRAIL)) ||
(cx + 1 < len && (row[cx + 1].flags & CELL_TRAIL))), 1)) {
row[cx] = (struct cell){cp,
t->inverse ? t->cur_bg : t->cur_fg,
@@ -88,8 +88,8 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags)
}
}
- if (TERM_EXPECT(t->pending_wrap, 0)) {
- row_set_wrapped(term_row(t, t->cursor_y), true);
+ if (WSAP_VTCORE_EXPECT(t->pending_wrap, 0)) {
+ row_set_wrapped(wsap_vtcore_row(t, t->cursor_y), true);
t->cursor_x = t->lr_margin_mode ? t->left_margin : 0;
sc_linefeed(t, 1);
t->pending_wrap = false;
@@ -102,10 +102,10 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags)
int cols = t->cols;
int right = t->lr_margin_mode ? t->right_margin : cols - 1;
- if (TERM_EXPECT(width == 2 && cols > 1 && cx == right && t->autowrap, 0)) {
- term_row_fill_gap(srow, cx);
+ if (WSAP_VTCORE_EXPECT(width == 2 && cols > 1 && cx == right && t->autowrap, 0)) {
+ wsap_vtcore_row_fill_gap(srow, cx);
clear_wide_edges(row, cx, right + 1, srow->len);
- row[cx] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, CELL_WRAP_PAD, 0 };
+ row[cx] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, CELL_WRAP_PAD, 0 };
srow->len = (uint16_t)cols;
srow->version++;
row_set_wrapped(srow, true);
@@ -125,10 +125,10 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags)
} else {
flags &= ~CELL_WIDE;
}
- term_row_fill_gap(srow, cx);
- if (TERM_EXPECT(t->insert_mode, 0)) {
+ wsap_vtcore_row_fill_gap(srow, cx);
+ if (WSAP_VTCORE_EXPECT(t->insert_mode, 0)) {
if (cx == srow->len)
- row[cx] = (struct cell){ ' ', TERM_COLOR_FG, TERM_COLOR_BG, 0, 0 };
+ row[cx] = (struct cell){ ' ', WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG, 0, 0 };
int move = right + 1 - cx - span;
if (move > 0)
memmove(&row[cx + span], &row[cx], (size_t)move * sizeof(struct cell));
@@ -155,7 +155,7 @@ void term_sc_print_glyph(struct term *t, uint32_t cp, int width, uint16_t flags)
}
}
-static inline struct cell *last_written_cell(struct term *t)
+static inline struct cell *last_written_cell(struct wsap_vtcore *t)
{
int right = (t->lr_margin_mode && t->cursor_x <= t->right_margin)
? t->right_margin : t->cols - 1;
@@ -163,7 +163,7 @@ static inline struct cell *last_written_cell(struct term *t)
if (t->lr_margin_mode && x < t->left_margin)
return NULL;
- struct srow *srow = term_row(t, t->cursor_y);
+ struct srow *srow = wsap_vtcore_row(t, t->cursor_y);
if (x < 0 || x >= srow->len)
return NULL;
int p = phys_row(t, t->cursor_y);
@@ -173,19 +173,19 @@ static inline struct cell *last_written_cell(struct term *t)
return &row[x];
}
-bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass)
+bool wsap_vtcore_sc_extend_cluster(struct wsap_vtcore *t, uint32_t cp, int klass)
{
if (!can_extend_cluster(t->last_char, cp, klass))
return false;
struct cell *prev = last_written_cell(t);
- uint32_t cps[TERM_GRAPHEME_MAX_LEN];
- int len = prev && prev->c > ' ' ? term_gstore_expand(t->gstore, prev->c, cps, TERM_GRAPHEME_MAX_LEN) : 0;
+ uint32_t cps[WSAP_VTCORE_GRAPHEME_MAX_LEN];
+ int len = prev && prev->c > ' ' ? wsap_vtcore_gstore_expand(t->gstore, prev->c, cps, WSAP_VTCORE_GRAPHEME_MAX_LEN) : 0;
if (!len)
return joins_cluster(cp, klass);
if (!cluster_joins(cps, len, cp, klass))
return false;
- if (len >= TERM_GRAPHEME_MAX_LEN)
+ if (len >= WSAP_VTCORE_GRAPHEME_MAX_LEN)
return true;
cps[len++] = cp;
@@ -196,15 +196,15 @@ bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass)
int span = (cell.flags & CELL_WIDE) && x + 1 < t->cols ? 2 : 1;
struct srow *srow = &t->scr.slot[p];
if (srow->len == x + span) {
- fill_cells(prev, span, TERM_COLOR_FG, TERM_COLOR_BG);
+ fill_cells(prev, span, WSAP_VTCORE_COLOR_FG, WSAP_VTCORE_COLOR_BG);
srow->len = (uint16_t)x;
} else {
fill_cells(prev, span, cell.fg, cell.bg);
}
t->cursor_x = x;
t->pending_wrap = false;
- t->last_char = term_gstore_intern(t->gstore, cps, len);
- term_sc_print_glyph(t, t->last_char, -1,
+ t->last_char = wsap_vtcore_gstore_intern(t->gstore, cps, len);
+ wsap_vtcore_sc_print_glyph(t, t->last_char, -1,
cell.flags & ~(CELL_WIDE | CELL_EMOJI | CELL_TEXT));
prev = last_written_cell(t);
@@ -221,22 +221,22 @@ bool term_sc_extend_cluster(struct term *t, uint32_t cp, int klass)
}
/* n blank default rows scroll off the top, after the screen rows. */
-static void push_blank_lines(struct term *t, size_t n)
+static void push_blank_lines(struct wsap_vtcore *t, size_t n)
{
if (screen_has_history(t)) {
- term_hist_push_blank(&t->hist, n);
+ wsap_vtcore_hist_push_blank(&t->hist, n);
} else {
t->scr.top_id += n;
t->scr.top_seg = 0;
}
}
-static void scroll_up_bce(struct term *t, size_t count)
+static void scroll_up_bce(struct wsap_vtcore *t, size_t count)
{
size_t rows = (size_t)t->rows;
if (t->alternate || count <= rows) {
for (size_t i = count < rows ? count : rows; i > 0; i--)
- term_screen_scroll_up(t);
+ wsap_vtcore_screen_scroll_up(t);
return;
}
size_t rem = count - rows;
@@ -244,7 +244,7 @@ static void scroll_up_bce(struct term *t, size_t count)
/* Rows past the history limit would leave again at once. */
size_t keep = screen_has_history(t) ? t->hist.line_limit : 0;
for (size_t i = rows + (rem < keep ? rem : keep); i > 0; i--)
- term_screen_scroll_up(t);
+ wsap_vtcore_screen_scroll_up(t);
return;
}
bool skip = screen_has_history(t) && rem >= t->hist.line_limit;
@@ -260,7 +260,7 @@ static void scroll_up_bce(struct term *t, size_t count)
push_blank_lines(t, count);
} else {
for (size_t i = 0; i < rows; i++)
- term_screen_scroll_up(t);
+ wsap_vtcore_screen_scroll_up(t);
push_blank_lines(t, rem);
}
if (t->prompt_y > 0)
@@ -269,12 +269,12 @@ static void scroll_up_bce(struct term *t, size_t count)
t->full_gen++;
}
-void term_sc_linefeed_slow(struct term *t, size_t n)
+void wsap_vtcore_sc_linefeed_slow(struct wsap_vtcore *t, size_t n)
{
if (n == 0)
return;
t->pending_wrap = false;
- term_row(t, t->cursor_y)->version++;
+ wsap_vtcore_row(t, t->cursor_y)->version++;
if (t->cursor_y > t->scroll_bottom) {
if (t->cursor_y + (int)n < t->rows)
@@ -292,23 +292,23 @@ void term_sc_linefeed_slow(struct term *t, size_t n)
size_t scroll = (size_t)(t->cursor_y + (int)n - t->scroll_bottom);
t->cursor_y = t->scroll_bottom;
- if (TERM_EXPECT(t->scroll_top == 0 && t->scroll_bottom == t->rows - 1, 1)) {
- if (TERM_EXPECT(scroll == 1, 1))
- term_screen_scroll_up(t);
+ if (WSAP_VTCORE_EXPECT(t->scroll_top == 0 && t->scroll_bottom == t->rows - 1, 1)) {
+ if (WSAP_VTCORE_EXPECT(scroll == 1, 1))
+ wsap_vtcore_screen_scroll_up(t);
else
scroll_up_bce(t, scroll);
} else if (t->scroll_top > 0 || t->alternate) {
int height = t->scroll_bottom - t->scroll_top + 1;
if (height <= 0) height = 1;
int count = scroll > (size_t)height ? height : (int)scroll;
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, count, false, false);
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, count, false, false);
} else {
int height = t->scroll_bottom - t->scroll_top + 1;
if (height <= 0) height = 1;
if (scroll <= (size_t)height) {
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, (int)scroll, false, true);
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, (int)scroll, false, true);
} else {
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, height, false, true);
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, height, false, true);
size_t rem = scroll - (size_t)height;
if (using_default_colors(t)) {
push_blank_lines(t, rem);
@@ -319,7 +319,7 @@ void term_sc_linefeed_slow(struct term *t, size_t n)
rem = cap;
while (rem > 0) {
int chunk = rem > (size_t)height ? height : (int)rem;
- term_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, chunk, false, true);
+ wsap_vtcore_screen_scroll_region(t, t->scroll_top, t->scroll_bottom, chunk, false, true);
rem -= (size_t)chunk;
}
}
@@ -327,7 +327,7 @@ void term_sc_linefeed_slow(struct term *t, size_t n)
}
}
-void term_sc_tab(struct term *t, int n)
+void wsap_vtcore_sc_tab(struct wsap_vtcore *t, int n)
{
int dir = n >= 0 ? 1 : -1;
int count = n >= 0 ? n : -n;
@@ -341,7 +341,7 @@ void term_sc_tab(struct term *t, int n)
t->cursor_x = prev > 0 ? prev : 0;
}
t->pending_wrap = false;
- struct srow *cur = term_row(t, t->cursor_y);
+ struct srow *cur = wsap_vtcore_row(t, t->cursor_y);
if (cur) cur->version++;
return;
}
@@ -352,7 +352,7 @@ void term_sc_tab(struct term *t, int n)
t->cursor_x = x < 0 ? 0 : x >= t->cols ? t->cols - 1 : x;
}
t->pending_wrap = false;
- struct srow *cur = term_row(t, t->cursor_y);
+ struct srow *cur = wsap_vtcore_row(t, t->cursor_y);
if (cur) cur->version++;
}
@@ -361,8 +361,8 @@ void term_sc_tab(struct term *t, int n)
static inline void sgr_cell_reset(struct cell *cell)
{
- cell->fg = TERM_COLOR_FG;
- cell->bg = TERM_COLOR_BG;
+ cell->fg = WSAP_VTCORE_COLOR_FG;
+ cell->bg = WSAP_VTCORE_COLOR_BG;
cell->flags &= (uint16_t)~CELL_SGR_FLAGS;
}
@@ -370,7 +370,7 @@ static inline void sgr_cell_underline(struct cell *cell, int style)
{
if (style < 0 || style > 5) style = 1;
cell->flags = (uint16_t)((cell->flags & ~CELL_ANY_UNDERLINE) |
- term_ul_flags[style]);
+ wsap_vtcore_ul_flags[style]);
}
static void apply_sgr_to_cell(struct cell *cell, const struct csi *csi, int first)
@@ -406,42 +406,42 @@ static void apply_sgr_to_cell(struct cell *cell, const struct csi *csi, int firs
i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok);
if (ok) cell->fg = color;
break;
- case 39: cell->fg = TERM_COLOR_FG; break;
+ case 39: cell->fg = WSAP_VTCORE_COLOR_FG; break;
case 48:
i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok);
if (ok) cell->bg = color;
break;
- case 49: cell->bg = TERM_COLOR_BG; break;
+ case 49: cell->bg = WSAP_VTCORE_COLOR_BG; break;
case 53: cell->flags |= CELL_OVERLINE; break;
case 55: cell->flags &= (uint16_t)~CELL_OVERLINE; break;
case 58:
i += sgr_extended_color(csi->params, csi->nparams, csi->subparams, i, &color, &ok);
break;
default:
- if ((unsigned)(v - 30) < 8) cell->fg = term_color_index(v - 30);
- else if ((unsigned)(v - 40) < 8) cell->bg = term_color_index(v - 40);
- else if ((unsigned)(v - 90) < 8) cell->fg = term_color_index(v - 90 + 8);
- else if ((unsigned)(v - 100) < 8) cell->bg = term_color_index(v - 100 + 8);
+ if ((unsigned)(v - 30) < 8) cell->fg = wsap_vtcore_color_index(v - 30);
+ else if ((unsigned)(v - 40) < 8) cell->bg = wsap_vtcore_color_index(v - 40);
+ else if ((unsigned)(v - 90) < 8) cell->fg = wsap_vtcore_color_index(v - 90 + 8);
+ else if ((unsigned)(v - 100) < 8) cell->bg = wsap_vtcore_color_index(v - 100 + 8);
break;
}
}
}
-static void deccara_row(struct term *t, int y, int x0, int x1, const struct csi *csi)
+static void deccara_row(struct wsap_vtcore *t, int y, int x0, int x1, const struct csi *csi)
{
int p = phys_row(t, y);
struct cell *row = row_cells(t, p);
- struct srow *srow = term_row(t, y);
+ struct srow *srow = wsap_vtcore_row(t, y);
int len = srow->len;
if (x0 > 0 && x0 < len && (row[x0].flags & CELL_TRAIL)) x0--;
if (x1 + 1 < t->cols && x1 < len && (row[x1].flags & CELL_WIDE)) x1++;
- term_row_fill_gap(srow, x1 + 1);
+ wsap_vtcore_row_fill_gap(srow, x1 + 1);
for (int x = x0; x <= x1; x++)
apply_sgr_to_cell(&row[x], csi, 4);
srow->version++;
}
-void term_sc_deccara(struct term *t, const struct csi *csi)
+void wsap_vtcore_sc_deccara(struct wsap_vtcore *t, const struct csi *csi)
{
int top = csi->params[0] > 0 ? csi->params[0] - 1 : 0;
int left = csi->nparams > 1 && csi->params[1] > 0 ? csi->params[1] - 1 : 0;
@@ -462,9 +462,9 @@ void term_sc_deccara(struct term *t, const struct csi *csi)
}
}
-void term_sc_decaln(struct term *t)
+void wsap_vtcore_sc_decaln(struct wsap_vtcore *t)
{
- struct cell fill = { .c = 'E', .fg = TERM_COLOR_FG, .bg = TERM_COLOR_BG };
+ struct cell fill = { .c = 'E', .fg = WSAP_VTCORE_COLOR_FG, .bg = WSAP_VTCORE_COLOR_BG };
struct cell *row0 = NULL;
for (int y = 0; y < t->rows; y++) {
int p = phys_row(t, y);
@@ -484,45 +484,45 @@ void term_sc_decaln(struct term *t)
sc_move(t, 0, 0);
}
-void term_sc_reset(struct term *t)
+void wsap_vtcore_sc_reset(struct wsap_vtcore *t)
{
t->cursor_x = t->cursor_y = 0;
- t->saved = term_saved_cursor_initial();
+ t->saved = wsap_vtcore_saved_cursor_initial();
t->prompt_y = -1;
t->has_prompt = false;
t->graphics = t->pending_wrap = false;
t->last_char = 0;
t->charsets[0] = t->charsets[1] = 'B';
t->charset_active = 0;
- term_tabs_clear(t);
- term_tabs_default(t);
- term_screen_erase_all(t);
+ wsap_vtcore_tabs_clear(t);
+ wsap_vtcore_tabs_default(t);
+ wsap_vtcore_screen_erase_all(t);
t->full_gen++;
}
-void term_sc_set_cursor_style(struct term *t, int ps)
+void wsap_vtcore_sc_set_cursor_style(struct wsap_vtcore *t, int ps)
{
if (ps == 0) {
t->cursor_style = t->default_cursor_style;
t->cursor_blink = t->default_cursor_blink;
} else if (ps >= 1 && ps <= 6) {
- t->cursor_style = ps < 3 ? TERM_CURSOR_BLOCK
- : ps < 5 ? TERM_CURSOR_UNDERLINE : TERM_CURSOR_BAR;
+ t->cursor_style = ps < 3 ? WSAP_VTCORE_CURSOR_BLOCK
+ : ps < 5 ? WSAP_VTCORE_CURSOR_UNDERLINE : WSAP_VTCORE_CURSOR_BAR;
t->cursor_blink = (ps & 1);
}
- term_row(t, t->cursor_y)->version++;
+ wsap_vtcore_row(t, t->cursor_y)->version++;
}
static inline bool next_byte_wraps(const char *buf, size_t len, size_t pos, uint32_t last)
{
if (pos >= len) return false;
uint32_t cp;
- if (!term_utf8_decode_one(buf + pos, len - pos, &cp)) return false;
- int w = term_text_class(cp);
+ if (!wsap_vtcore_utf8_decode_one(buf + pos, len - pos, &cp)) return false;
+ int w = wsap_vtcore_text_class(cp);
return w > 0 && !can_extend_cluster(last, cp, w);
}
-static void flush_orig_rows(struct term *t, struct screen *s,
+static void flush_orig_rows(struct wsap_vtcore *t, struct screen *s,
int *orig_y, int *orig_rem, int count)
{
int y = *orig_y;
@@ -556,8 +556,8 @@ static void flush_orig_rows(struct term *t, struct screen *s,
}
}
if (lines) {
- term_hist_push_ascii_lf(&t->hist, (const char *)base, ends, lines);
- if (t->view.anchor.active) term_hist_view_note_push(&t->view, &t->hist, t->cols);
+ wsap_vtcore_hist_push_ascii_lf(&t->hist, (const char *)base, ends, lines);
+ if (t->view.anchor.active) wsap_vtcore_hist_view_note_push(&t->view, &t->hist, t->cols);
y = closed;
continue;
}
@@ -578,15 +578,15 @@ static void flush_orig_rows(struct term *t, struct screen *s,
};
}
if (n) {
- term_hist_push_ascii_lines(&t->hist, q, n, NULL);
- if (t->view.anchor.active) term_hist_view_note_push(&t->view, &t->hist, t->cols);
+ wsap_vtcore_hist_push_ascii_lines(&t->hist, q, n, NULL);
+ if (t->view.anchor.active) wsap_vtcore_hist_view_note_push(&t->view, &t->hist, t->cols);
y += n;
- } else term_screen_push_row(t, screen_get_row(s, y++));
+ } else wsap_vtcore_screen_push_row(t, screen_get_row(s, y++));
}
}
struct stream_emit_ctx {
- struct term *term;
+ struct wsap_vtcore *term;
struct screen *screen;
struct hist_ascii_line *q;
const struct pen_attr *attr;
@@ -603,7 +603,7 @@ static void flush_stream_queue(struct stream_emit_ctx *ctx)
if (ctx->orig_rem > 0)
flush_orig_rows(ctx->term, ctx->screen, &ctx->orig_y, &ctx->orig_rem, ctx->orig_rem);
int flush_n = ctx->q_count - ctx->q_cap;
- term_hist_push_ascii_lines(&ctx->term->hist, ctx->q, flush_n, ctx->attr);
+ wsap_vtcore_hist_push_ascii_lines(&ctx->term->hist, ctx->q, flush_n, ctx->attr);
if (ctx->q_cap > 0) {
if (flush_n >= ctx->q_cap)
memcpy(ctx->q, ctx->q + flush_n, (size_t)ctx->q_cap * sizeof(ctx->q[0]));
@@ -617,14 +617,14 @@ static void flush_stream_queue(struct stream_emit_ctx *ctx)
static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx,
const char *src, int bulk_lines)
{
- struct term *t = ctx->term;
+ struct wsap_vtcore *t = ctx->term;
struct screen *s = ctx->screen;
int cols = ctx->cols;
- if (TERM_EXPECT(t->pending_wrap, 0)) {
+ if (WSAP_VTCORE_EXPECT(t->pending_wrap, 0)) {
row_set_wrapped(screen_get_row(s, s->rows - 1), true);
t->pending_wrap = false;
t->cursor_x = 0;
- term_screen_scroll_up(t);
+ wsap_vtcore_screen_scroll_up(t);
}
if (bulk_lines < ctx->q_cap) {
const char *p = src;
@@ -640,13 +640,13 @@ static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx,
if (ctx->orig_rem > 0)
flush_orig_rows(t, s, &ctx->orig_y, &ctx->orig_rem, ctx->orig_rem);
if (ctx->q_count > 0) {
- term_hist_push_ascii_lines(&t->hist, ctx->q, ctx->q_count, ctx->attr);
+ wsap_vtcore_hist_push_ascii_lines(&t->hist, ctx->q, ctx->q_count, ctx->attr);
ctx->flushed_scrolled += (size_t)ctx->q_count;
ctx->q_count = 0;
}
int hist_rows = bulk_lines - ctx->q_cap;
if (hist_rows > 0) {
- term_hist_push_ascii(&t->hist, src, hist_rows * cols, ctx->attr, true);
+ wsap_vtcore_hist_push_ascii(&t->hist, src, hist_rows * cols, ctx->attr, true);
ctx->flushed_scrolled += (size_t)hist_rows;
}
const char *sp = src + (size_t)hist_rows * (size_t)cols;
@@ -655,31 +655,31 @@ static inline void emit_stream_bulk_wrapped(struct stream_emit_ctx *ctx,
ctx->q_count = ctx->q_cap;
}
-static inline TERM_ALWAYS_INLINE void emit_stream_row_fast(struct stream_emit_ctx *ctx,
+static inline WSAP_VTCORE_ALWAYS_INLINE void emit_stream_row_fast(struct stream_emit_ctx *ctx,
const char *row_ptr,
int row_len, bool row_wrapped)
{
- if (TERM_EXPECT(ctx->q_count == 256, 0))
+ if (WSAP_VTCORE_EXPECT(ctx->q_count == 256, 0))
flush_stream_queue(ctx);
ctx->q[ctx->q_count++] = (struct hist_ascii_line){
row_ptr, (uint16_t)row_len, (uint8_t)row_wrapped
};
}
-static inline TERM_ALWAYS_INLINE void emit_stream_row(struct stream_emit_ctx *ctx,
+static inline WSAP_VTCORE_ALWAYS_INLINE void emit_stream_row(struct stream_emit_ctx *ctx,
const char *row_ptr,
int row_len, bool row_wrapped)
{
- if (TERM_EXPECT(ctx->term->pending_wrap, 0)) {
+ if (WSAP_VTCORE_EXPECT(ctx->term->pending_wrap, 0)) {
row_set_wrapped(screen_get_row(ctx->screen, ctx->screen->rows - 1), true);
ctx->term->pending_wrap = false;
ctx->term->cursor_x = 0;
- term_screen_scroll_up(ctx->term);
+ wsap_vtcore_screen_scroll_up(ctx->term);
}
emit_stream_row_fast(ctx, row_ptr, row_len, row_wrapped);
}
-static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf, size_t len)
+static WSAP_VTCORE_NOINLINE size_t stream_ascii_wrapped(struct wsap_vtcore *t, const char *buf, size_t len)
{
int limit = len > INT32_MAX ? INT32_MAX : (int)len;
int run = scan_ascii_run(buf, limit);
@@ -700,7 +700,7 @@ static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf
int orig_y = 0, orig_rem = old_rows;
flush_orig_rows(t, s, &orig_y, &orig_rem, old_count);
int extra = count - (keep - orig_rem);
- if (extra) term_hist_push_ascii(&t->hist, buf, extra * cols, NULL, true);
+ if (extra) wsap_vtcore_hist_push_ascii(&t->hist, buf, extra * cols, NULL, true);
s->top = (s->top + scrolls % rows) % rows;
const char *src = buf + extra * cols;
uint8_t *copy_dst = NULL;
@@ -740,10 +740,10 @@ static TERM_NOINLINE size_t stream_ascii_wrapped(struct term *t, const char *buf
return (size_t)count * cols;
}
-#if defined(TERM_KERNEL_AVX512)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
/* Cut *count at the first line longer than half a history page. Check
* whole blocks of 32 lines. Return the line where the check stopped. */
-TERM_TARGET_AVX512
+WSAP_VTCORE_TARGET_AVX512
static int long_lines_avx512(const uint16_t *ends, int *count)
{
int j = 0;
@@ -753,7 +753,7 @@ static int long_lines_avx512(const uint16_t *ends, int *count)
uint32_t bad = _mm512_cmpgt_epu16_mask(_mm512_sub_epi16(end, start),
_mm512_set1_epi16(HIST_PAGE_USABLE / 2));
if (bad) {
- *count = j + term_ctz32(bad);
+ *count = j + wsap_vtcore_ctz32(bad);
break;
}
}
@@ -761,7 +761,7 @@ static int long_lines_avx512(const uint16_t *ends, int *count)
}
#endif
-static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, size_t len)
+static WSAP_VTCORE_NOINLINE size_t stream_ascii_lf(struct wsap_vtcore *t, const char *buf, size_t len)
{
int limit = len < UINT16_MAX ? (int)len : UINT16_MAX;
size_t need = ((size_t)limit + 65) * sizeof(uint16_t);
@@ -774,8 +774,8 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz
uint16_t *ends = t->ascii_ends.data;
int count = scan_ascii_lf(buf, limit, ends);
int j = 0;
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
j = long_lines_avx512(ends, &count);
#endif
for (; j < count; j++) {
@@ -809,9 +809,9 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz
t->ascii_tail.cap = tail_bytes;
}
memcpy(tail_data, buf + source_start, tail_bytes);
- term_hist_push_ascii_lf(&t->hist, buf, ends, first);
+ wsap_vtcore_hist_push_ascii_lf(&t->hist, buf, ends, first);
if (skip)
- term_hist_push_ascii(&t->hist, buf + ends[first], skip, NULL, true);
+ wsap_vtcore_hist_push_ascii(&t->hist, buf + ends[first], skip, NULL, true);
uint32_t last = t->last_char;
for (int j = count; j > 0; j--) {
if (ends[j] - ends[j - 1] > 1) {
@@ -851,8 +851,8 @@ static TERM_NOINLINE size_t stream_ascii_lf(struct term *t, const char *buf, siz
/* Bit i of the result is set when buf[i] is not printable ASCII. *nl gets
* the line feeds. Both cover 64 bytes. */
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
static inline uint64_t line_masks_avx512(const char *buf, uint64_t *nl)
{
__m512i v = _mm512_loadu_si512((const void *)buf);
@@ -862,8 +862,8 @@ static inline uint64_t line_masks_avx512(const char *buf, uint64_t *nl)
}
#endif
-#if defined(TERM_KERNEL_AVX2)
-TERM_TARGET_AVX2
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+WSAP_VTCORE_TARGET_AVX2
static inline uint64_t line_masks_avx2(const char *buf, uint64_t *nl)
{
uint64_t lf = 0, controls = 0;
@@ -883,16 +883,16 @@ static inline uint64_t line_masks_avx2(const char *buf, uint64_t *nl)
static inline uint64_t line_masks(const char *buf, uint64_t *nl)
{
-#if defined(TERM_KERNEL_AVX2)
- if (term_use_avx2())
+#if defined(WSAP_VTCORE_KERNEL_AVX2)
+ if (wsap_vtcore_use_avx2())
return line_masks_avx2(buf, nl);
#endif
uint64_t lf = 0, controls = 0;
#if defined(__aarch64__)
for (int b = 0; b < 64; b += 16) {
uint8x16_t v = vld1q_u8((const uint8_t *)buf + b);
- lf |= (uint64_t)term_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << b;
- controls |= (uint64_t)term_lane_bits(vcgeq_u8(
+ lf |= (uint64_t)wsap_vtcore_lane_bits(vceqq_u8(v, vdupq_n_u8('\n'))) << b;
+ controls |= (uint64_t)wsap_vtcore_lane_bits(vcgeq_u8(
vsubq_u8(v, vdupq_n_u8(0x20)), vdupq_n_u8(0x7f - 0x20))) << b;
}
#else
@@ -916,7 +916,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx)
if (loop_scrolled == 0)
return;
- struct term *t = ctx->term;
+ struct wsap_vtcore *t = ctx->term;
struct screen *s = ctx->screen;
int rows = s->rows;
@@ -936,7 +936,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx)
int flush_n = k;
if (flush_n > 0) {
- term_hist_push_ascii_lines(&t->hist, ctx->q, flush_n, ctx->attr);
+ wsap_vtcore_hist_push_ascii_lines(&t->hist, ctx->q, flush_n, ctx->attr);
}
int skip_rows = tail_rows - needed;
@@ -944,7 +944,7 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx)
struct hist_ascii_line pr = ctx->q[k];
int skip_bytes = skip_rows * cols;
if (skip_bytes > (int)pr.len) skip_bytes = (int)pr.len;
- term_hist_push_ascii(&t->hist, pr.ptr, skip_bytes, ctx->attr, true);
+ wsap_vtcore_hist_push_ascii(&t->hist, pr.ptr, skip_bytes, ctx->attr, true);
}
if (ctx->orig_rem == 0) {
@@ -1042,20 +1042,20 @@ static void stream_queue_finish(struct stream_emit_ctx *ctx)
/* One body for every level. isa is a constant in each copy below, so each
* copy keeps only its own kernels. */
-static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, const char *buf,
+static inline WSAP_VTCORE_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct wsap_vtcore *t, const char *buf,
size_t len, int isa)
{
(void)isa;
struct screen *s = &t->scr;
int rows = s->rows;
- if (TERM_EXPECT(rows > 256, 0))
+ if (WSAP_VTCORE_EXPECT(rows > 256, 0))
return 0;
size_t i = 0;
int cols = t->cols;
- uint32_t flags = term_flags_pad(t);
+ uint32_t flags = wsap_vtcore_flags_pad(t);
bool autowrap = t->autowrap;
- bool lnm = term_lnm(t);
+ bool lnm = wsap_vtcore_lnm(t);
int last_char = (int)t->last_char;
struct pen_attr attr = {
@@ -1088,8 +1088,8 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co
size_t scan = i;
while (scan + 64 <= len) {
uint64_t nl, controls;
-#if defined(TERM_KERNEL_AVX512)
- if (isa == TERM_ISA_AVX512)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (isa == WSAP_VTCORE_ISA_AVX512)
controls = line_masks_avx512(buf + scan, &nl);
else
#endif
@@ -1097,7 +1097,7 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co
if (controls != nl)
break;
while (nl) {
- size_t end = scan + (size_t)term_ctz64(nl);
+ size_t end = scan + (size_t)wsap_vtcore_ctz64(nl);
if (!autowrap && end - i > (size_t)cols)
goto narrow_done;
if (end > i)
@@ -1116,8 +1116,8 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co
narrow_done:
if (i >= len)
break;
-#if defined(TERM_KERNEL_AVX512)
- if (isa == TERM_ISA_AVX512 && TERM_EXPECT(!lnm && !t->pending_wrap, 1)) {
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (isa == WSAP_VTCORE_ISA_AVX512 && WSAP_VTCORE_EXPECT(!lnm && !t->pending_wrap, 1)) {
while (i + 64 <= len) {
uint64_t nl;
uint64_t mask = line_masks_avx512(buf + i, &nl);
@@ -1165,7 +1165,7 @@ narrow_done:
for (int line = 0; line < 3 && consumed < 64; line++) {
uint64_t rest = mask >> consumed;
if (!rest) break;
- int run = term_ctz64(rest);
+ int run = wsap_vtcore_ctz64(rest);
if (run > cols) break;
int pos = consumed + run;
int eol = buf[i + pos] == '\n' && lnm ? 1 :
@@ -1189,13 +1189,13 @@ narrow_done:
int limit = len - i > (size_t)cols ? cols : (int)(len - i);
int run = scan_ascii_run(buf + i, limit);
int eol = 0;
- if (TERM_EXPECT(i + run + 1 < len && buf[i + run] == '\r' && buf[i + run + 1] == '\n', 1)) {
+ if (WSAP_VTCORE_EXPECT(i + run + 1 < len && buf[i + run] == '\r' && buf[i + run + 1] == '\n', 1)) {
eol = 2;
} else if (i + run < len && buf[i + run] == '\n' && lnm) {
eol = 1;
}
- if (TERM_EXPECT(eol > 0, 1)) {
+ if (WSAP_VTCORE_EXPECT(eol > 0, 1)) {
if (run > 0)
last_char = (unsigned char)buf[i + run - 1];
emit_stream_row(&ctx, buf + i, run, false);
@@ -1228,7 +1228,7 @@ narrow_done:
emit_stream_row(&ctx, buf + i, run, true);
i += (size_t)run;
}
-#if defined(TERM_KERNEL_AVX512)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
done:
#endif
if (i == 0)
@@ -1244,30 +1244,30 @@ done:
return i;
}
-#if defined(TERM_KERNEL_AVX512)
-TERM_TARGET_AVX512
-static TERM_NOINLINE size_t bulk_ascii_lines_avx512(struct term *t, const char *buf, size_t len)
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+WSAP_VTCORE_TARGET_AVX512
+static WSAP_VTCORE_NOINLINE size_t bulk_ascii_lines_avx512(struct wsap_vtcore *t, const char *buf, size_t len)
{
- return bulk_ascii_lines_body(t, buf, len, TERM_ISA_AVX512);
+ return bulk_ascii_lines_body(t, buf, len, WSAP_VTCORE_ISA_AVX512);
}
#endif
-static TERM_NOINLINE size_t bulk_ascii_lines_base(struct term *t, const char *buf, size_t len)
+static WSAP_VTCORE_NOINLINE size_t bulk_ascii_lines_base(struct wsap_vtcore *t, const char *buf, size_t len)
{
- return bulk_ascii_lines_body(t, buf, len, TERM_ISA_BASE);
+ return bulk_ascii_lines_body(t, buf, len, WSAP_VTCORE_ISA_BASE);
}
-size_t term_sc_bulk_ascii_lines(struct term *t, const char *buf, size_t len)
+size_t wsap_vtcore_sc_bulk_ascii_lines(struct wsap_vtcore *t, const char *buf, size_t len)
{
- if (TERM_EXPECT(t->scr.rows > 256, 0)) return 0;
- if (len >= 1024 && t->autowrap && using_default_colors(t) && !term_flags_pad(t)) {
+ if (WSAP_VTCORE_EXPECT(t->scr.rows > 256, 0)) return 0;
+ if (len >= 1024 && t->autowrap && using_default_colors(t) && !wsap_vtcore_flags_pad(t)) {
size_t done = 0;
- if (!term_lnm(t)) done = stream_ascii_wrapped(t, buf, len);
+ if (!wsap_vtcore_lnm(t)) done = stream_ascii_wrapped(t, buf, len);
else if (!t->pending_wrap) done = stream_ascii_lf(t, buf, len);
if (done) return done;
}
-#if defined(TERM_KERNEL_AVX512)
- if (term_use_avx512())
+#if defined(WSAP_VTCORE_KERNEL_AVX512)
+ if (wsap_vtcore_use_avx512())
return bulk_ascii_lines_avx512(t, buf, len);
#endif
return bulk_ascii_lines_base(t, buf, len);