htop
htop copied to clipboard
"Memory & Swap" meter in Text style spans whole terminal width
The "Memory & Swap" meter in Text style spans the whole terminal width.
This happens in the current master branch. Only Text style is affected; Bar, Graph and LED styles are all fine.
Screenshot:

Is this the only meter in that row? Does this happen if there's another meter right next to it?
@BenBE I tested it just now. If I place a meter on the right of the Memory & Swap meter, The Memory & Swap meter reduces its display width of the Text style. So you won't see the bug if you place a meter right next to the Memory & Swap meter,
It's a feature, see #484.
The MemorySwap meter is a bit special cause it is not strictly left-aligned, but aligns itself on the given width. We could exempt this special one though.
diff --git a/Header.c b/Header.c
index 8940b36..25bb81a 100644
--- a/Header.c
+++ b/Header.c
@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "CPUMeter.h"
#include "DynamicMeter.h"
#include "Macros.h"
+#include "MemorySwapMeter.h"
#include "Object.h"
#include "Platform.h"
#include "ProvideCurses.h"
@@ -212,7 +213,11 @@ void Header_draw(const Header* this) {
Meter* meter = (Meter*) Vector_get(meters, i);
float actualWidth = colWidth;
- if (meter->mode == TEXT_METERMODE) {
+
+ /* Let meters in text mode expand to the right on empty neighbors;
+ except for non-left-aligned ones. */
+ if (meter->mode == TEXT_METERMODE &&
+ !Object_isA(&meter->super, &MemorySwapMeter_class.super)) {
for (int j = 1; j < meter->columnWidthCount; j++) {
actualWidth += (float)width * HeaderLayout_layouts[this->headerLayout].widths[col + j] / 100.0F;
}
@cgzones The implementation is not consistent.
- Why only MemorySwapMeter has this behavior and not other meters that split itself to multiple sub-columns (such as the multiple CPU meters)?
- The LED_METERMODE should demonstrate the same spanning behavior. Otherwise it's better not have the "feature" at all.
@cgzones @Explorer09 this issue appears to be a little stalled. At this point it seems to me its not likely to be a trivial fix, nor sufficiently high priority for us to continue to wait on a resolution for htop-3.1.0. If you disagree let me know, otherwise I'll continue on with the release early next week, and work on this issue can proceed for merging thereafter. Thanks!
@natoscott DLange agrees with your analysis, suggests to apply the patch from https://github.com/htop-dev/htop/issues/796#issuecomment-918489632 as an interim improvement though.
Forwarded to 3.1.1 in case somebody wants to look at the LED Meter mode for col spanning as per https://github.com/htop-dev/htop/issues/796#issuecomment-918699336