From 942ea4267d0362fb0031ed995195d9c4e45bcdfb Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 25 Jun 2009 16:01:26 +0000 Subject: Trying to predict the cursor position for UTF-8 output in the same way as for normal eight-bit output is wrong, separate it into a different function. Fixes spacing when mixing UTF-8 with some escape sequences, notably the way w3m does it. --- tty.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tty.c') diff --git a/tty.c b/tty.c index 47868d52..457c10dd 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.4 2009/06/03 23:30:40 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.5 2009/06/24 16:01:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -418,6 +418,23 @@ tty_putc(struct tty *tty, u_char ch) write(tty->log_fd, &ch, 1); } +void +tty_pututf8(struct tty *tty, const struct grid_utf8 *gu) +{ + u_int i, width; + + for (i = 0; i < UTF8_SIZE; i++) { + if (gu->data[i] == 0xff) + break; + buffer_write8(tty->out, gu->data[i]); + if (tty->log_fd != -1) + write(tty->log_fd, &gu->data[i], 1); + } + + width = utf8_width(gu->data); + tty->cx += width; +} + void tty_set_title(struct tty *tty, const char *title) { @@ -922,11 +939,7 @@ tty_cell( } /* Otherwise, write UTF-8. */ - for (i = 0; i < UTF8_SIZE; i++) { - if (gu->data[i] == 0xff) - break; - tty_putc(tty, gu->data[i]); - } + tty_pututf8(tty, gu); } void -- cgit