summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmadeusz Sławiński <amade@asmblr.net>2014-04-26 18:29:02 +0200
committerAmadeusz Sławiński <amade@asmblr.net>2014-04-26 18:29:02 +0200
commit3b2b8ee6ae360bbaa676cc8e1f1f91dbfad94ae2 (patch)
treee6e51a200e34703281f20a5586201992efe6a974
parentceb7b5121a9da505fdad35bccf0fe421f81b0fd2 (diff)
downloadscreen-3b2b8ee6ae360bbaa676cc8e1f1f91dbfad94ae2.tar.gz
fix-utf8-status-padding-bug
Ensure that multibyte UTF8 characters are counted correctly when calculating and displaying the caption and hardstatus lines. Based on an earlier version by Kees Cook <address@hidden> Signed-off-by: Dustin Kirkland <address@hidden> Signed-off-by: Amadeusz Sławiński <amade@asmblr.net>
-rw-r--r--src/display.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/display.c b/src/display.c
index 64ea856..8161e1e 100644
--- a/src/display.c
+++ b/src/display.c
@@ -2163,7 +2163,7 @@ int start, max;
{
int chars = strlen_onscreen((unsigned char *)(s + start), (unsigned char *)(s + max));
D_encoding = 0;
- PutWinMsg(s, start, max);
+ PutWinMsg(s, start, max + ((max - start) - chars)); /* Multibyte count */
D_encoding = UTF8;
D_x -= (max - chars); /* Yak! But this is necessary to count for
the fact that not every byte represents a
@@ -2257,11 +2257,15 @@ void
RefreshHStatus()
{
char *buf;
-
+#ifdef UTF8
+ int extrabytes = strlen(hstatusstring) - strlen_onscreen(hstatusstring, NULL);
+#else
+ int extrabytes = 0;
+#endif
evdeq(&D_hstatusev);
if (D_status == STATUS_ON_HS)
return;
- buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP, &D_hstatusev, 0);
+ buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP + extrabytes, &D_hstatusev, 0);
if (buf && *buf)
{
ShowHStatus(buf);
@@ -2356,8 +2360,13 @@ int y, from, to, isblank;
{
if (y == cv->c_ye + 1 && from >= cv->c_xs && from <= cv->c_xe)
{
+#ifdef UTF8
+ int extrabytes = strlen(captionstring) - strlen_onscreen(captionstring, NULL);
+#else
+ int extrabytes = 0;
+#endif
p = Layer2Window(cv->c_layer);
- buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP), &cv->c_captev, 0);
+ buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP) + extrabytes, &cv->c_captev, 0);
if (cv->c_captev.timeout.tv_sec)
evenq(&cv->c_captev);
xx = to > cv->c_xe ? cv->c_xe : to;
@@ -2366,7 +2375,7 @@ int y, from, to, isblank;
SetRendition(&mchar_so);
if (l > xx - cv->c_xs + 1)
l = xx - cv->c_xs + 1;
- l = PrePutWinMsg(buf, from - cv->c_xs, l);
+ l = PrePutWinMsg(buf, from - cv->c_xs, l + extrabytes);
from = cv->c_xs + l;
for (; from <= xx; from++)
PUTCHARLP(' ');