summaryrefslogtreecommitdiff
path: root/src/core.h
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 14:46:44 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 14:46:44 +0300
commit1e69599900a753e2d7275d7ba714202b7d9c843e (patch)
tree13416f651319145aa5dbdd85b9947bec4858b366 /src/core.h
parent5ab6b560e8528c27ba934b90f94b1828b7771e27 (diff)
Eliminate pen style and history stream parameter smuggling
- Introduce struct text_pen bundling (fg, bg, sl) across screen and core - Reduce text_append from 9 to 7 parameters - Reduce text_commit from 8 to 6 parameters - Reduce hist_runs_add_pen from 5 to 3 parameters - Reduce sc_text_ascii and sc_ascii_fast from 6 to 4 parameters - Remove unused fg, bg parameters from mark_row_blank - Introduce struct hist_stream_state in src/hist.c, reducing stream_lines from 9 to 5 params and lf_rows from 10 to 6 params - Introduce struct hist_view_pos in src/hist_view.h, reducing term_hist_view_row_pos from 9 to 7 params
Diffstat (limited to 'src/core.h')
-rw-r--r--src/core.h36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/core.h b/src/core.h
index beec4e0..79e6eb9 100644
--- a/src/core.h
+++ b/src/core.h
@@ -205,10 +205,9 @@ static inline void sc_text_advance(struct term *t, int x, int cols, int avail)
}
}
-/* Append ASCII at the cursor, with the pen fg, bg, sl (flags | link << 16),
+/* 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, uint32_t fg, uint32_t bg,
- uint32_t sl)
+static inline int sc_text_ascii(struct term *t, const char *s, int n, struct text_pen pen)
{
if (TERM_EXPECT(t->insert_mode || t->lr_margin_mode, 0))
return 0;
@@ -225,7 +224,7 @@ static inline int sc_text_ascii(struct term *t, const char *s, int n, uint32_t f
int take = n < avail ? n : avail;
if (take <= 0)
return 0;
- text_append(row, (const uint8_t *)s, take, take, take, HLINE_NARROW, fg, bg, sl);
+ text_append(row, (const uint8_t *)s, take, take, take, HLINE_NARROW, pen);
t->last_char = (unsigned char)s[take - 1];
sc_text_advance(t, x, take, avail);
return take;
@@ -233,11 +232,9 @@ static inline int sc_text_ascii(struct term *t, const char *s, int n, uint32_t f
static inline void sc_print_ascii(struct term *t, const char *s, int n)
{
- uint32_t fg = TERM_EXPECT(t->inverse, 0) ? t->cur_bg : t->cur_fg;
- uint32_t bg = TERM_EXPECT(t->inverse, 0) ? t->cur_fg : t->cur_bg;
- uint32_t flags = term_flags_pad(t);
+ struct text_pen pen = term_text_pen(t);
- for (int k; n > 0 && (k = sc_text_ascii(t, s, n, fg, bg, flags)) > 0; s += k, n -= k) {}
+ 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);
@@ -251,7 +248,7 @@ static inline void sc_print_ascii(struct term *t, const char *s, int n)
if (take <= 0)
break;
}
- put_ascii_chunk(span.cells, s, take, fg, bg, flags);
+ 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;
s += take;
@@ -261,7 +258,7 @@ static inline void sc_print_ascii(struct term *t, const char *s, int n)
/* 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,
- uint32_t fg, uint32_t bg, uint32_t flags_pad)
+ struct text_pen pen)
{
int cx = t->cursor_x;
if (TERM_EXPECT(t->pending_wrap || t->insert_mode ||
@@ -270,7 +267,7 @@ static inline bool sc_ascii_fast(struct term *t, const char *s, int n,
return false;
struct srow *row = term_row(t, t->cursor_y);
if (row->kind == ROW_TEXT || (row->len == 0 && cx == 0)) {
- if (sc_text_ascii(t, s, n, fg, bg, flags_pad) == n)
+ if (sc_text_ascii(t, s, n, pen) == n)
return true;
if (row->kind == ROW_TEXT)
return false;
@@ -282,7 +279,7 @@ static inline bool sc_ascii_fast(struct term *t, const char *s, int n,
if (TERM_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, fg, bg, flags_pad);
+ put_ascii_chunk(cells + cx, s, n, pen.fg, pen.bg, pen.sl);
cx += n;
if (cx > len)
row->len = (uint16_t)cx;
@@ -299,8 +296,7 @@ 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, uint32_t fg, uint32_t bg,
- uint32_t flags_pad)
+static inline bool sc_put1_fast(struct term *t, char ch, struct text_pen pen)
{
int cx = t->cursor_x;
int cols = t->cols;
@@ -312,12 +308,12 @@ static inline bool sc_put1_fast(struct term *t, char ch, uint32_t fg, uint32_t b
if (row->kind == ROW_TEXT) {
struct text_row *tr = &row->text;
if (TERM_EXPECT(cx != tr->cells || !tr->cells || cx + 1 == cols, 0))
- return sc_text_ascii(t, &ch, 1, fg, bg, flags_pad) == 1;
+ 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;
tr->cells++;
- hist_runs_add_pen(&tr->runs, fg, bg, flags_pad, 1);
- if (flags_pad >> 16)
+ hist_runs_add_pen(&tr->runs, pen, 1);
+ if (pen.sl >> 16)
tr->flags |= HLINE_HAS_LINK;
if (tr->cells > row->len)
row->len = tr->cells;
@@ -327,7 +323,7 @@ static inline bool sc_put1_fast(struct term *t, char ch, uint32_t fg, uint32_t b
return true;
}
if (row->len == 0 && cx == 0) {
- if (sc_text_ascii(t, &ch, 1, fg, bg, flags_pad) == 1)
+ if (sc_text_ascii(t, &ch, 1, pen) == 1)
return true;
}
int len = row->len;
@@ -338,8 +334,8 @@ static inline bool sc_put1_fast(struct term *t, char ch, uint32_t fg, uint32_t b
(cx + 1 < len && (cells[cx + 1].flags & CELL_TRAIL)), 0))
return false;
- cells[cx] = (struct cell){ (uint8_t)ch, fg, bg,
- (uint16_t)flags_pad, (uint16_t)(flags_pad >> 16) };
+ cells[cx] = (struct cell){ (uint8_t)ch, pen.fg, pen.bg,
+ (uint16_t)pen.sl, (uint16_t)(pen.sl >> 16) };
t->last_char = (uint8_t)ch;
cx++;
if (cx > len)