summaryrefslogtreecommitdiff
path: root/src/core.h
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:01 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:01 +0300
commitdcebf9c7f954a55350b68d0ead1935612c4e2e05 (patch)
tree3eb3e9f6154c6760bcb89a565f8ddc8f8b66cb90 /src/core.h
parentbd8222e615134c3ec5e7a07b6b1fa97c9bd4a471 (diff)
Rename the library to wsap_vtcore
ncurses installs <term.h> and defines struct term. In a file that includes both headers, an ncurses TERMINAL * and this library's terminal are silently the same type. The name wsap_vtcore avoids the clash. The public header is now <wsap_vtcore/wsap_vtcore.h>. Every global symbol uses the wsap_vtcore_ prefix, every macro uses WSAP_VTCORE_, and the shared library is libwsap_vtcore.so.0. The default terminal name is now "wsap_vtcore". The ISA override variable is WSAP_VTCORE_ISA. No other behavior changes. The amalgamation writes wsap_vtcore.c and wsap_vtcore.h. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/core.h')
-rw-r--r--src/core.h132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/core.h b/src/core.h
index 823a57d..56f0520 100644
--- a/src/core.h
+++ b/src/core.h
@@ -18,28 +18,28 @@ struct span {
};
/* Begin writing a span of cells. Settle cursor row, repair left edge. */
-static inline struct span sc_span_begin(struct term *t, int want);
+static inline struct span sc_span_begin(struct wsap_vtcore *t, int want);
/* Finish writing a span of cells. Repair right edge, raise len, bump gen. */
-static inline void sc_span_end(struct term *t, struct span *s, int cols,
+static inline void sc_span_end(struct wsap_vtcore *t, struct span *s, int cols,
uint8_t row_flags, uint32_t last);
/* Print ASCII characters through span and SIMD chunking. */
-static inline void sc_print_ascii(struct term *t, const char *s, int n);
+static inline void sc_print_ascii(struct wsap_vtcore *t, const char *s, int n);
/* Print one glyph (single codepoint or cluster handle). */
-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);
-static inline void sc_print_cell(struct term *t, uint32_t cp, int width, uint16_t flags)
+static inline void sc_print_cell(struct wsap_vtcore *t, uint32_t cp, int width, uint16_t flags)
{
- 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,
@@ -60,43 +60,43 @@ static inline void sc_print_cell(struct term *t, uint32_t cp, int width, uint16_
}
}
}
- term_sc_print_glyph(t, cp, width, flags);
+ wsap_vtcore_sc_print_glyph(t, cp, width, flags);
}
/* Extend the last printed glyph into a grapheme cluster. */
-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);
/* Multi-line or region-constrained line feed helper. */
-void term_sc_linefeed_slow(struct term *t, size_t n);
+void wsap_vtcore_sc_linefeed_slow(struct wsap_vtcore *t, size_t n);
/* Line feed: move down or scroll with BCE. */
-static inline void sc_linefeed(struct term *t, size_t n)
+static inline void sc_linefeed(struct wsap_vtcore *t, size_t n)
{
- if (TERM_EXPECT(n == 1 && t->scroll_top == 0 &&
+ if (WSAP_VTCORE_EXPECT(n == 1 && t->scroll_top == 0 &&
t->scroll_bottom == t->rows - 1, 1)) {
t->pending_wrap = false;
- term_row(t, t->cursor_y)->version++;
- if (TERM_EXPECT(t->cursor_y == t->rows - 1, 1))
- term_screen_scroll_up(t);
+ wsap_vtcore_row(t, t->cursor_y)->version++;
+ if (WSAP_VTCORE_EXPECT(t->cursor_y == t->rows - 1, 1))
+ wsap_vtcore_screen_scroll_up(t);
else
t->cursor_y++;
return;
}
- term_sc_linefeed_slow(t, n);
+ wsap_vtcore_sc_linefeed_slow(t, n);
}
/* Carriage return: move cursor to left margin. */
-static inline void sc_cr(struct term *t)
+static inline void sc_cr(struct wsap_vtcore *t)
{
t->pending_wrap = false;
if (t->cursor_x != 0) {
t->cursor_x = 0;
- term_row(t, t->cursor_y)->version++;
+ wsap_vtcore_row(t, t->cursor_y)->version++;
}
}
/* Move cursor to (x, y), margin-aware. */
-static inline void sc_move(struct term *t, int x, int y)
+static inline void sc_move(struct wsap_vtcore *t, int x, int y)
{
t->pending_wrap = false;
if (x < 0) x = 0;
@@ -109,16 +109,16 @@ static inline void sc_move(struct term *t, int x, int y)
return;
t->cursor_x = x;
t->cursor_y = y;
- term_row(t, old_y)->version++;
+ wsap_vtcore_row(t, old_y)->version++;
if (y != old_y)
- term_row(t, y)->version++;
+ wsap_vtcore_row(t, y)->version++;
}
/* Advance cursor by n tab stops. */
-void term_sc_tab(struct term *t, int n);
+void wsap_vtcore_sc_tab(struct wsap_vtcore *t, int n);
/* Erase cells in span [from, to) on physical row y. */
-static inline void sc_erase_span(struct term *t, int y, int from, int to)
+static inline void sc_erase_span(struct wsap_vtcore *t, int y, int from, int to)
{
t->pending_wrap = false;
if (to > t->cols) to = t->cols;
@@ -128,50 +128,50 @@ static inline void sc_erase_span(struct term *t, int y, int from, int to)
}
/* Restore saved cursor state and position. */
-static inline void sc_restore_cursor(struct term *t, const struct term_saved_cursor *s)
+static inline void sc_restore_cursor(struct wsap_vtcore *t, const struct wsap_vtcore_saved_cursor *s)
{
- term_cursor_apply(t, s);
+ wsap_vtcore_cursor_apply(t, s);
sc_move(t, s->x, s->y);
t->pending_wrap = s->pending_wrap;
}
/* Change attributes in a rectangular or stream area (DECCARA). */
-void term_sc_deccara(struct term *t, const struct csi *csi);
+void wsap_vtcore_sc_deccara(struct wsap_vtcore *t, const struct csi *csi);
/* Screen alignment pattern (DECALN). */
-void term_sc_decaln(struct term *t);
+void wsap_vtcore_sc_decaln(struct wsap_vtcore *t);
/* Reset screen and cursor state for full reset (RIS). */
-void term_sc_reset(struct term *t);
+void wsap_vtcore_sc_reset(struct wsap_vtcore *t);
/* Set cursor style (DECSCUSR). */
-void term_sc_set_cursor_style(struct term *t, int ps);
+void wsap_vtcore_sc_set_cursor_style(struct wsap_vtcore *t, int ps);
/* Bulk streaming of ASCII lines with raw rows and skip-ahead. */
-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);
/* Fast CSI parser. */
-int term_try_fast_csi(struct term *t, const char *buf, size_t rem);
+int wsap_vtcore_try_fast_csi(struct wsap_vtcore *t, const char *buf, size_t rem);
-static inline struct span sc_span_begin(struct term *t, int want)
+static inline struct span sc_span_begin(struct wsap_vtcore *t, int want)
{
(void)want;
- 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;
}
- struct srow *row = term_row(t, t->cursor_y);
- if (TERM_EXPECT(row->kind != ROW_CELLS, 0))
+ struct srow *row = wsap_vtcore_row(t, t->cursor_y);
+ if (WSAP_VTCORE_EXPECT(row->kind != ROW_CELLS, 0))
srow_settle(row, t->cols);
int cx = t->cursor_x;
- term_row_fill_gap(row, cx);
+ wsap_vtcore_row_fill_gap(row, cx);
int len = row->len;
- if (TERM_EXPECT(cx < len && (row->cells[cx].flags & CELL_TRAIL), 0))
+ if (WSAP_VTCORE_EXPECT(cx < len && (row->cells[cx].flags & CELL_TRAIL), 0))
fill_cells(row->cells + cx - 1, 1, row->cells[cx - 1].fg, row->cells[cx - 1].bg);
- int right = TERM_EXPECT(t->lr_margin_mode, 0) ? t->right_margin : t->cols - 1;
+ int right = WSAP_VTCORE_EXPECT(t->lr_margin_mode, 0) ? t->right_margin : t->cols - 1;
int avail = right + 1 > cx ? right + 1 - cx : 0;
return (struct span){
.row = row,
@@ -182,21 +182,21 @@ static inline struct span sc_span_begin(struct term *t, int want)
};
}
-static inline void sc_span_end(struct term *t, struct span *s, int cols,
+static inline void sc_span_end(struct wsap_vtcore *t, struct span *s, int cols,
uint8_t row_flags, uint32_t last)
{
struct srow *row = s->row;
int end_x = s->x + cols;
- if (TERM_EXPECT(end_x < s->old_len && (row->cells[end_x].flags & CELL_TRAIL), 0))
+ if (WSAP_VTCORE_EXPECT(end_x < s->old_len && (row->cells[end_x].flags & CELL_TRAIL), 0))
fill_cells(row->cells + end_x, 1, row->cells[end_x].fg, row->cells[end_x].bg);
if (end_x > s->old_len)
row->len = (uint16_t)end_x;
- if (TERM_EXPECT(row_flags != 0, 0))
+ if (WSAP_VTCORE_EXPECT(row_flags != 0, 0))
row->flags |= row_flags;
row->version++;
t->last_char = last;
- if (TERM_EXPECT(cols < s->avail, 1)) {
+ if (WSAP_VTCORE_EXPECT(cols < s->avail, 1)) {
t->cursor_x = end_x;
t->pending_wrap = false;
} else {
@@ -206,7 +206,7 @@ static inline void sc_span_end(struct term *t, struct span *s, int cols,
}
/* Move the cursor after cols columns written at x, of avail. */
-static inline void sc_text_advance(struct term *t, int x, int cols, int avail)
+static inline void sc_text_advance(struct wsap_vtcore *t, int x, int cols, int avail)
{
if (cols < avail) {
t->cursor_x = x + cols;
@@ -219,12 +219,12 @@ static inline void sc_text_advance(struct term *t, int x, int cols, int avail)
/* Append ASCII at the cursor, with the pen,
* when the cursor row takes text. Return the bytes taken. */
-static inline int sc_text_ascii(struct term *t, const char *s, int n, struct text_pen pen)
+static inline int sc_text_ascii(struct wsap_vtcore *t, const char *s, int n, struct text_pen pen)
{
- if (TERM_EXPECT(t->insert_mode || t->lr_margin_mode, 0))
+ if (WSAP_VTCORE_EXPECT(t->insert_mode || t->lr_margin_mode, 0))
return 0;
if (t->pending_wrap) {
- row_set_wrapped(term_row(t, t->cursor_y), true);
+ row_set_wrapped(wsap_vtcore_row(t, t->cursor_y), true);
t->cursor_x = 0;
sc_linefeed(t, 1);
t->pending_wrap = false;
@@ -242,16 +242,16 @@ static inline int sc_text_ascii(struct term *t, const char *s, int n, struct tex
return take;
}
-static inline void sc_print_ascii(struct term *t, const char *s, int n)
+static inline void sc_print_ascii(struct wsap_vtcore *t, const char *s, int n)
{
- struct text_pen pen = term_text_pen(t);
+ struct text_pen pen = wsap_vtcore_text_pen(t);
for (int k; n > 0 && (k = sc_text_ascii(t, s, n, pen)) > 0; s += k, n -= k) {}
while (n > 0) {
struct span span = sc_span_begin(t, n);
int take = n < span.avail ? n : span.avail;
- if (TERM_EXPECT(take <= 0, 0)) {
+ if (WSAP_VTCORE_EXPECT(take <= 0, 0)) {
t->pending_wrap = t->autowrap;
if (!t->autowrap)
break;
@@ -262,33 +262,33 @@ static inline void sc_print_ascii(struct term *t, const char *s, int n)
}
put_ascii_chunk(span.cells, s, take, pen.fg, pen.bg, pen.sl);
sc_span_end(t, &span, take, 0, (unsigned char)s[take - 1]);
- if (TERM_EXPECT(n <= take, 1)) break;
+ if (WSAP_VTCORE_EXPECT(n <= take, 1)) break;
s += take;
n -= take;
}
}
/* Write a short ASCII span without settling an already writable row. */
-static inline bool sc_ascii_fast(struct term *t, const char *s, int n,
+static inline bool sc_ascii_fast(struct wsap_vtcore *t, const char *s, int n,
struct text_pen pen)
{
int cx = t->cursor_x;
- if (TERM_EXPECT(t->pending_wrap || t->insert_mode ||
+ if (WSAP_VTCORE_EXPECT(t->pending_wrap || t->insert_mode ||
t->lr_margin_mode || t->inverse ||
n <= 0 || n > t->cols - cx, 0))
return false;
- struct srow *row = term_row(t, t->cursor_y);
+ struct srow *row = wsap_vtcore_row(t, t->cursor_y);
if (row->kind == ROW_TEXT || (row->len == 0 && cx == 0)) {
if (sc_text_ascii(t, s, n, pen) == n)
return true;
if (row->kind == ROW_TEXT)
return false;
}
- if (TERM_EXPECT(row->kind != ROW_CELLS || cx > row->len, 0))
+ if (WSAP_VTCORE_EXPECT(row->kind != ROW_CELLS || cx > row->len, 0))
return false;
int len = row->len;
struct cell *cells = row->cells;
- if (TERM_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) ||
+ if (WSAP_VTCORE_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) ||
(cx + n < len && (cells[cx + n].flags & CELL_TRAIL)), 0))
return false;
put_ascii_chunk(cells + cx, s, n, pen.fg, pen.bg, pen.sl);
@@ -308,18 +308,18 @@ static inline bool sc_ascii_fast(struct term *t, const char *s, int n,
}
/* Fast inline check for 1-character write (fg-char fast path). */
-static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen)
+static inline bool sc_put1_fast(struct wsap_vtcore *t, char ch, struct text_pen pen)
{
int cx = t->cursor_x;
int cols = t->cols;
- if (TERM_EXPECT(t->pending_wrap | t->insert_mode | t->lr_margin_mode | t->inverse, 0))
+ if (WSAP_VTCORE_EXPECT(t->pending_wrap | t->insert_mode | t->lr_margin_mode | t->inverse, 0))
return false;
- if (TERM_EXPECT(cx >= cols, 0))
+ if (WSAP_VTCORE_EXPECT(cx >= cols, 0))
return false;
- struct srow *row = term_row(t, t->cursor_y);
+ struct srow *row = wsap_vtcore_row(t, t->cursor_y);
if (row->kind == ROW_TEXT) {
struct text_row *tr = &row->text;
- if (TERM_EXPECT(cx != tr->cells || !tr->cells || cx + 1 == cols, 0))
+ if (WSAP_VTCORE_EXPECT(cx != tr->cells || !tr->cells || cx + 1 == cols, 0))
return sc_text_ascii(t, &ch, 1, pen) == 1;
/* One character in the middle of a text row. */
tr->text[tr->text_len++] = (uint8_t)ch;
@@ -339,10 +339,10 @@ static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen)
return true;
}
int len = row->len;
- if (TERM_EXPECT(cx > len, 0))
+ if (WSAP_VTCORE_EXPECT(cx > len, 0))
return false;
struct cell *cells = row->cells;
- if (TERM_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) ||
+ if (WSAP_VTCORE_EXPECT((cx < len && (cells[cx].flags & CELL_TRAIL)) ||
(cx + 1 < len && (cells[cx + 1].flags & CELL_TRAIL)), 0))
return false;
@@ -353,7 +353,7 @@ static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen)
if (cx > len)
row->len = (uint16_t)cx;
row->version++;
- if (TERM_EXPECT(cx < cols, 1)) {
+ if (WSAP_VTCORE_EXPECT(cx < cols, 1)) {
t->cursor_x = cx;
} else {
t->cursor_x = cols - 1;