]> granicus.if.org Git - procps-ng/commitdiff
top: added utf8 multibyte support to additional fields
authorJim Warner <james.warner@comcast.net>
Wed, 23 Dec 2020 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Mon, 28 Dec 2020 21:48:23 +0000 (08:48 +1100)
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>
top/top.c

index 8deeefaad47a65441ec8af8bc61244a0d010972d..7da896b024cc2015e47181fce91a23b49c086b4f 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -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;