Large PID causes misalignment of columns
Large PID numbers cause misaligned columns. Htop should either truncate PIDs to say 5 digits, or dynamically adjust the PID column's width.
Example of misalignment when PIDs are longer than 5 (in my case up to 8).
As far as I can see, only PIDs of threads in macOS can appear misaligned like this.
yes, the are hardcoded 5 digits at https://github.com/htop-dev/htop/blob/main/darwin/Platform.c#L216 That used to be correct but then is seems to be INT_MAX now. Did not find any docs.
diff --git a/darwin/Platform.c b/darwin/Platform.c
index 84ebc395..c083eedd 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "darwin/Platform.h"
#include <errno.h>
+#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
@@ -212,8 +213,10 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
}
pid_t Platform_getMaxPid(void) {
- /* http://opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/sys/proc_internal.hh */
- return 99999;
+ /* Used to be 99999 as per
+ https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/proc_internal.h#L758
+ */
+ return INT_MAX;
}
static double Platform_setCPUAverageValues(Meter* mtr) {
works but is ugly. Dynamically scaling (on every refresh) is ugly, too.
Don't we have the auto-sizing feature for columns for exactly that reason?
We typically set Row_setPidColumnWidth(Platform_getMaxPid()); only in Machine_init. It does not make much sense to change the PID width every iteration as this would wiggle the screen contents right and left. We could make it only grow on MacOSX.
Or jump to 10 chars width when we see a PID > 99999.
Would be useful to understand when the > 99999 PIDs happen and when they don't.
Or we just track the largest PID we've seen so far, thus growing, but never shrinking the PID column; starting with 5 digits …
@BenBE Any updates on this ...?
Or we just track the largest PID we've seen so far, thus growing, but never shrinking the PID column; starting with 5 digits …
I'd like to try to implement this, if no one is working on it yet.
@a17sol: Sure, go for it. Just make it proper cross-platform, please. No AI-compiles-and-fire PRs.