summaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c95
1 files changed, 20 insertions, 75 deletions
diff --git a/src/core.c b/src/core.c
index 7bca76e..b352be1 100644
--- a/src/core.c
+++ b/src/core.c
@@ -596,7 +596,6 @@ struct stream_emit_ctx {
int orig_y;
int orig_rem;
int cols;
- bool def_pen;
};
static void flush_stream_queue(struct stream_emit_ctx *ctx)
@@ -604,7 +603,6 @@ 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;
- (void)ctx->def_pen;
term_hist_push_ascii_lines(&ctx->term->hist, ctx->q, flush_n, ctx->attr);
if (ctx->q_cap > 0) {
if (flush_n >= ctx->q_cap)
@@ -1066,8 +1064,6 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co
.flags = (uint16_t)flags,
.link = (uint16_t)(flags >> 16),
};
- bool def_pen = (t->cur_fg == TERM_COLOR_FG && t->cur_bg == TERM_COLOR_BG && flags == 0);
-
if (t->pending_wrap &&
(len == 0 || (unsigned char)buf[0] < 0x20 || (unsigned char)buf[0] >= 0x7f))
return 0;
@@ -1084,7 +1080,6 @@ static inline TERM_ALWAYS_INLINE size_t bulk_ascii_lines_body(struct term *t, co
.orig_y = 0,
.orig_rem = rows - 1,
.cols = cols,
- .def_pen = def_pen,
};
while (i < len) {
@@ -1165,78 +1160,28 @@ narrow_done:
continue;
}
- int p1 = term_ctz64(mask);
- if (p1 > cols)
- break;
-
- int eol1 = 0;
- if (buf[i + p1] == '\n' && lnm) {
- eol1 = 1;
- } else if (buf[i + p1] == '\r' && (p1 + 1 < 64 ? buf[i + p1 + 1] == '\n' : (i + p1 + 1 < len && buf[i + p1 + 1] == '\n'))) {
- eol1 = 2;
- } else if (p1 < cols) {
- goto done;
- } else {
- break;
- }
-
- if (p1 > 0)
- last_char = (unsigned char)buf[i + p1 - 1];
- emit_stream_row_fast(&ctx, buf + i, p1, false);
-
- int next_start = p1 + eol1;
- int last_consumed = next_start;
-
- if (next_start < 64) {
- uint64_t mask2 = mask >> next_start;
- if (mask2 != 0) {
- int rel_p2 = term_ctz64(mask2);
- int p2 = next_start + rel_p2;
- if (rel_p2 <= cols) {
- int eol2 = 0;
- if (buf[i + p2] == '\n' && lnm) {
- eol2 = 1;
- } else if (buf[i + p2] == '\r' && (p2 + 1 < 64 ? buf[i + p2 + 1] == '\n' : (i + p2 + 1 < len && buf[i + p2 + 1] == '\n'))) {
- eol2 = 2;
- }
-
- if (eol2 > 0) {
- if (rel_p2 > 0)
- last_char = (unsigned char)buf[i + p2 - 1];
- emit_stream_row_fast(&ctx, buf + i + next_start, rel_p2, false);
-
- int next_start2 = p2 + eol2;
- last_consumed = next_start2;
-
- if (next_start2 < 64) {
- uint64_t mask3 = mask >> next_start2;
- if (mask3 != 0) {
- int rel_p3 = term_ctz64(mask3);
- int p3 = next_start2 + rel_p3;
- if (rel_p3 <= cols) {
- int eol3 = 0;
- if (buf[i + p3] == '\n' && lnm) {
- eol3 = 1;
- } else if (buf[i + p3] == '\r' && (p3 + 1 < 64 ? buf[i + p3 + 1] == '\n' : (i + p3 + 1 < len && buf[i + p3 + 1] == '\n'))) {
- eol3 = 2;
- }
-
- if (eol3 > 0) {
- if (rel_p3 > 0)
- last_char = (unsigned char)buf[i + p3 - 1];
- emit_stream_row_fast(&ctx, buf + i + next_start2, rel_p3, false);
-
- last_consumed = p3 + eol3;
- }
- }
- }
- }
- }
- }
+ /* Consume up to three complete lines from this mask. */
+ int consumed = 0;
+ for (int line = 0; line < 3 && consumed < 64; line++) {
+ uint64_t rest = mask >> consumed;
+ if (!rest) break;
+ int run = term_ctz64(rest);
+ if (run > cols) break;
+ int pos = consumed + run;
+ int eol = buf[i + pos] == '\n' && lnm ? 1 :
+ buf[i + pos] == '\r' && i + pos + 1 < len &&
+ buf[i + pos + 1] == '\n' ? 2 : 0;
+ if (!eol) {
+ if (line == 0 && run < cols) goto done;
+ break;
}
+ if (run > 0)
+ last_char = (unsigned char)buf[i + pos - 1];
+ emit_stream_row_fast(&ctx, buf + i + consumed, run, false);
+ consumed = pos + eol;
}
-
- i += (size_t)last_consumed;
+ if (!consumed) break;
+ i += (size_t)consumed;
}
if (i >= len) break;
}