diff options
Diffstat (limited to 'src/core.h')
| -rw-r--r-- | src/core.h | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -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) |
