summaryrefslogtreecommitdiffstats
path: root/screen-write.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2023-09-01 17:06:27 +0100
committerThomas Adam <thomas@xteddy.org>2023-09-01 17:06:27 +0100
commit1aec420465eab1cf6e4666851f950621e006b26d (patch)
treebe86e9bbe9a07d46a047611542581b87b1d5e9ee /screen-write.c
parentd682ef88e6eab4d256adf441d29f8e873ea292da (diff)
parent9456258ccc03a1a959cfb7d020011d751b39bb1b (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'screen-write.c')
-rw-r--r--screen-write.c64
1 files changed, 37 insertions, 27 deletions
diff --git a/screen-write.c b/screen-write.c
index d51f4c4d..9f9d7ace 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -1935,46 +1935,37 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
{
struct screen *s = ctx->s;
struct grid *gd = s->grid;
- const struct utf8_data *ud = &gc->data;
- const struct utf8_data zwj = { "\342\200\215", 0, 3, 0 };
+ struct grid_cell copy;
+ const struct utf8_data *ud = &gc->data, *previous = NULL, *combine;
struct grid_line *gl;
struct grid_cell_entry *gce;
struct grid_cell tmp_gc, now_gc;
struct tty_ctx ttyctx;
u_int sx = screen_size_x(s), sy = screen_size_y(s);
- u_int width = gc->data.width, xx, last, cx, cy;
+ u_int width = ud->width, xx, last, cx, cy;
int selected, skip = 1;
/* Ignore padding cells. */
if (gc->flags & GRID_FLAG_PADDING)
return;
- /*
- * If this is a zero width joiner, set the flag so the next character
- * will be treated as zero width and appended. Note that we assume a
- * ZWJ will not change the width - the width of the first character is
- * used.
- */
- if (ud->size == 3 && memcmp(ud->data, "\342\200\215", 3) == 0) {
- log_debug("zero width joiner at %u,%u", s->cx, s->cy);
- ctx->flags |= SCREEN_WRITE_ZWJ;
+ /* Check if this cell needs to be combined with the previous cell. */
+ if (ctx->flags & SCREEN_WRITE_COMBINE)
+ previous = &ctx->previous;
+ switch (utf8_try_combined(ud, previous, &combine, &width)) {
+ case UTF8_DISCARD_NOW:
+ log_debug("%s: UTF8_DISCARD_NOW (width %u)", __func__, width);
+ ctx->flags &= ~SCREEN_WRITE_COMBINE;
return;
- }
-
- /*
- * If the width is zero, combine onto the previous character. We always
- * combine with the cell to the left of the cursor position. In theory,
- * the application could have moved the cursor somewhere else, but if
- * they are silly enough to do that, who cares?
- */
- if (ctx->flags & SCREEN_WRITE_ZWJ) {
- screen_write_collect_flush(ctx, 0, __func__);
- screen_write_combine(ctx, &zwj, &xx, &cx);
- }
- if (width == 0 || (ctx->flags & SCREEN_WRITE_ZWJ)) {
- ctx->flags &= ~SCREEN_WRITE_ZWJ;
+ case UTF8_WRITE_NOW:
+ log_debug("%s: UTF8_WRITE_NOW (width %u)", __func__, width);
+ ctx->flags &= ~SCREEN_WRITE_COMBINE;
+ break;
+ case UTF8_COMBINE_NOW:
+ log_debug("%s: UTF8_COMBINE_NOW (width %u)", __func__, width);
screen_write_collect_flush(ctx, 0, __func__);
- if ((gc = screen_write_combine(ctx, ud, &xx, &cx)) != NULL) {
+ gc = screen_write_combine(ctx, combine, &xx, &cx);
+ if (gc != NULL) {
cy = s->cy;
screen_write_set_cursor(ctx, xx, s->cy);
screen_write_initctx(ctx, &ttyctx, 0);
@@ -1982,8 +1973,27 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
tty_write(tty_cmd_cell, &ttyctx);
s->cx = cx; s->cy = cy;
}
+ ctx->flags &= ~SCREEN_WRITE_COMBINE;
return;
+ case UTF8_WRITE_MAYBE_COMBINE:
+ log_debug("%s: UTF8_WRITE_MAYBE_COMBINE (width %u)", __func__,
+ width);
+ utf8_copy(&ctx->previous, ud);
+ ctx->flags |= SCREEN_WRITE_COMBINE;
+ break;
+ case UTF8_DISCARD_MAYBE_COMBINE:
+ log_debug("%s: UTF8_DISCARD_MAYBE_COMBINE (width %u)", __func__,
+ width);
+ utf8_copy(&ctx->previous, ud);
+ ctx->flags |= SCREEN_WRITE_COMBINE;
+ return;
+ }
+ if (width != ud->width) {
+ memcpy(&copy, gc, sizeof copy);
+ copy.data.width = width;
+ gc = &copy;
}
+ ud = NULL;
/* Flush any existing scrolling. */
screen_write_collect_flush(ctx, 1, __func__);