htop icon indicating copy to clipboard operation
htop copied to clipboard

"Memory & Swap" meter in Text style spans whole terminal width

Open Explorer09 opened this issue 4 years ago • 7 comments

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: htop-memory-and-swap-meter

Explorer09 avatar Sep 12 '21 23:09 Explorer09

Is this the only meter in that row? Does this happen if there's another meter right next to it?

BenBE avatar Sep 13 '21 07:09 BenBE

@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,

Explorer09 avatar Sep 13 '21 09:09 Explorer09

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 avatar Sep 13 '21 19:09 cgzones

@cgzones The implementation is not consistent.

  1. Why only MemorySwapMeter has this behavior and not other meters that split itself to multiple sub-columns (such as the multiple CPU meters)?
  2. The LED_METERMODE should demonstrate the same spanning behavior. Otherwise it's better not have the "feature" at all.

Explorer09 avatar Sep 14 '21 00:09 Explorer09

@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 avatar Sep 17 '21 07:09 natoscott

@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.

fasterit avatar Sep 17 '21 12:09 fasterit

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

fasterit avatar Sep 21 '21 06:09 fasterit