top: added utf8 multibyte support to additional fields

When any process' command line contains multibyte utf8
characters, two separate display problems could arise.

1. If that COMMAND column is not displayed as the very
last field, then field(s) to the right are misaligned.

2. Even when last, should utf8 string length (not that
display length) exceed allowable screen width, it will
nonetheless suffer from improper premature truncation.

Number 1 is less of a concern since the cmdline column
is likely to always be the last field to be displayed,
if only to enable right and left scrolling provisions.

Number 2 is much more likely to occur, especially with
additional fields which might be shown before COMMAND.
Or, forest view child tasks can yield the same effect.

So, this commit will permit the correct utf8 multibyte
display regardless of field position or string length.

And, we'll bring top into line with the ps program for
additional fields potentially subject to utf8 display.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2020-12-23 00:00:00 -06:00 committed by Craig Small
parent 91897e7d2c
commit 9c212a7e77

View File

@ -5919,21 +5919,21 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) {
case EU_USN: // PIDS_ID_SUSER
cp = make_str_utf8(rSv(i, str), W, Js, i);
break;
/* str, make_str with varialbe width */
/* str, make_str_utf8 with varialbe width */
case EU_CGN: // PIDS_CGNAME
case EU_CGR: // PIDS_CGROUP
case EU_ENV: // PIDS_ENVIRON
case EU_EXE: // PIDS_EXE
case EU_SGD: // PIDS_SUPGIDS
makeVAR(rSv(i, str));
break;
/* str, make_str_utf8 with varialbe width */
case EU_SGN: // PIDS_SUPGROUPS
varUTF8(rSv(EU_SGN, str));
varUTF8(rSv(i, str));
break;
/* str, make_str with varialbe width */
case EU_SGD: // PIDS_SUPGIDS
makeVAR(rSv(EU_SGD, str));
break;
/* str, make_str with varialbe width + additional decoration */
case EU_CMD: // PIDS_CMD or PIDS_CMDLINE
makeVAR(forest_colour(q, p));
varUTF8(forest_colour(q, p));
break;
default: // keep gcc happy
continue;