top: enable bottom 'window' multi-byte char capability
If the special bottom 'window' routines remain unaware of potential multi-byte characters, that heading could be truncated prematurely and unnecessary blank line(s) added to the reserved rows at the bottom of a display. So, in both cases, this patch will now account for any difference between string lengths and display columns. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
ef1d82cf18
commit
723b418cd4
19
top/top.c
19
top/top.c
@ -4954,10 +4954,14 @@ static int bot_focus_str (const char *hdr, const char *str) {
|
|||||||
if (n >= sizeof(Bot_buf)) n = sizeof(Bot_buf) - 1;
|
if (n >= sizeof(Bot_buf)) n = sizeof(Bot_buf) - 1;
|
||||||
if (!*str || !strcmp(str, "-")) strcpy(Bot_buf, "n/a");
|
if (!*str || !strcmp(str, "-")) strcpy(Bot_buf, "n/a");
|
||||||
else memccpy(Bot_buf, str, '\0', n);
|
else memccpy(Bot_buf, str, '\0', n);
|
||||||
Bot_rsvd = 1 + BOT_RSVD + (strlen(Bot_buf) / Screen_cols);
|
Bot_rsvd = 1 + BOT_RSVD + ((strlen(Bot_buf) - utf8_delta(Bot_buf)) / Screen_cols);
|
||||||
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
||||||
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
||||||
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
snprintf(tmp, sizeof(tmp), "%s%s%-*s"
|
||||||
|
, tg2(0, SCREEN_ROWS)
|
||||||
|
, Curwin->capclr_hdr
|
||||||
|
, Screen_cols + utf8_delta(hdr)
|
||||||
|
, hdr);
|
||||||
putp(tmp);
|
putp(tmp);
|
||||||
}
|
}
|
||||||
// now fmtmk is safe to use ...
|
// now fmtmk is safe to use ...
|
||||||
@ -5001,16 +5005,21 @@ static int bot_focus_strv (const char *hdr, const char **strv) {
|
|||||||
memcpy(Bot_buf, strv[0], n);
|
memcpy(Bot_buf, strv[0], n);
|
||||||
if (!Bot_buf[0] || (!strcmp(Bot_buf, "-") && n <= sizeof(char *)))
|
if (!Bot_buf[0] || (!strcmp(Bot_buf, "-") && n <= sizeof(char *)))
|
||||||
strcpy(Bot_buf, "n/a");
|
strcpy(Bot_buf, "n/a");
|
||||||
for (nsav= 0, p = Bot_buf; strv[nsav] != NULL; nsav++) {
|
for (nsav= 0, p = Bot_buf, x = 0; strv[nsav] != NULL; nsav++) {
|
||||||
p += strlen(strv[nsav]) + 1;
|
p += strlen(strv[nsav]) + 1;
|
||||||
if ((p - Bot_buf) >= sizeof(Bot_buf))
|
if ((p - Bot_buf) >= sizeof(Bot_buf))
|
||||||
break;
|
break;
|
||||||
n = p - Bot_buf;
|
x += utf8_delta(strv[nsav]);
|
||||||
}
|
}
|
||||||
|
n = (p - Bot_buf) - (x + 1);
|
||||||
Bot_rsvd = 1 + BOT_RSVD + (n / Screen_cols);
|
Bot_rsvd = 1 + BOT_RSVD + (n / Screen_cols);
|
||||||
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
if (Bot_rsvd > maxRSVD) Bot_rsvd = maxRSVD;
|
||||||
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
// somewhere down call chain fmtmk() may be used, so we'll old school it
|
||||||
snprintf(tmp, sizeof(tmp), "%s%s%-*s", tg2(0, SCREEN_ROWS), Curwin->capclr_hdr, Screen_cols, hdr);
|
snprintf(tmp, sizeof(tmp), "%s%s%-*s"
|
||||||
|
, tg2(0, SCREEN_ROWS)
|
||||||
|
, Curwin->capclr_hdr
|
||||||
|
, Screen_cols + utf8_delta(hdr)
|
||||||
|
, hdr);
|
||||||
putp(tmp);
|
putp(tmp);
|
||||||
}
|
}
|
||||||
// now fmtmk is safe to use ...
|
// now fmtmk is safe to use ...
|
||||||
|
Loading…
Reference in New Issue
Block a user