summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2021-07-07 16:57:03 +1000
committerNathan Scott <nathans@redhat.com>2021-07-08 10:56:05 +1000
commit01f5b892785014db30db4d6b4b7c23e042c7ffe4 (patch)
tree785c3eec2534ed4654cfda34b3780c91e01372d7 /Meter.c
parent149774209be588fb0da001e5d9cac224862cc5da (diff)
Pretty-print values in the PCP DynamicMeter code
Several improvements to the way values are displayed in the PCP platform DynamicMeter implementation: - handle the initial 'caption' setting as with regular meters, this required a new meter callback because we no longer have just a single meter caption for the DynamicMeter case - if no label is provided for a metric in a configuration file use the short form metric name as a fallback - honour the suffix setting in the configuration file - convert metric values to the canonical units for htop (kbyte and seconds), and use Meter_humanUnit when it makes sense to do so. Also improves the handling of fatal string error messages in a couple of places, thanks to BenBE for the review feedback.
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/Meter.c b/Meter.c
index 0052773c..5e3a00d0 100644
--- a/Meter.c
+++ b/Meter.c
@@ -153,11 +153,12 @@ ListItem* Meter_toListItem(const Meter* this, bool moving) {
/* ---------- TextMeterMode ---------- */
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
+ const char* caption = Meter_getCaption(this);
attrset(CRT_colors[METER_TEXT]);
- mvaddnstr(y, x, this->caption, w - 1);
+ mvaddnstr(y, x, caption, w - 1);
attrset(CRT_colors[RESET_COLOR]);
- int captionLen = strlen(this->caption);
+ int captionLen = strlen(caption);
x += captionLen;
w -= captionLen;
if (w <= 0)
@@ -174,10 +175,11 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
static const char BarMeterMode_characters[] = "|#*@$%&.";
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
+ const char* caption = Meter_getCaption(this);
w -= 2;
attrset(CRT_colors[METER_TEXT]);
int captionLen = 3;
- mvaddnstr(y, x, this->caption, captionLen);
+ mvaddnstr(y, x, caption, captionLen);
x += captionLen;
w -= captionLen;
attrset(CRT_colors[BAR_BORDER]);
@@ -306,9 +308,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
GraphMeterMode_pixPerRow = PIXPERROW_ASCII;
}
+ const char* caption = Meter_getCaption(this);
attrset(CRT_colors[METER_TEXT]);
int captionLen = 3;
- mvaddnstr(y, x, this->caption, captionLen);
+ mvaddnstr(y, x, caption, captionLen);
x += captionLen;
w -= captionLen;
@@ -393,8 +396,9 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, ATTR_UNUSED int w) {
#endif
y + 2;
attrset(CRT_colors[LED_COLOR]);
- mvaddstr(yText, x, this->caption);
- int xx = x + strlen(this->caption);
+ const char* caption = Meter_getCaption(this);
+ mvaddstr(yText, x, caption);
+ int xx = x + strlen(caption);
int len = RichString_sizeVal(out);
for (int i = 0; i < len; i++) {
int c = RichString_getCharVal(out, i);

© 2014-2024 Faster IT GmbH | imprint | privacy policy