summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2015-06-12 09:53:18 +0200
committerChristian Hesse <mail@eworm.de>2015-08-27 06:13:27 +0200
commitcf47f4fca1bab93b81a2fb32cb548cb1722bb0f4 (patch)
tree57f5b7fdf872b7ac7d75f16245c9f08c06e834f8
parent6f58fbc5dd091557129895bbd0a05335e411d19e (diff)
use dynamic units for text display
Signed-off-by: Christian Hesse <mail@eworm.de>
-rw-r--r--MemoryMeter.c19
-rw-r--r--SwapMeter.c17
-rw-r--r--SwapMeter.h5
3 files changed, 10 insertions, 31 deletions
diff --git a/MemoryMeter.c b/MemoryMeter.c
index ba9dcc9c..dae56b5e 100644
--- a/MemoryMeter.c
+++ b/MemoryMeter.c
@@ -40,22 +40,17 @@ static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
static void MemoryMeter_display(Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
- int k = 1024; const char* format = "%ldM ";
- long int totalMem = this->total / k;
- long int usedMem = this->values[0] / k;
- long int buffersMem = this->values[1] / k;
- long int cachedMem = this->values[2] / k;
RichString_write(out, CRT_colors[METER_TEXT], ":");
- sprintf(buffer, format, totalMem);
+ Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
- sprintf(buffer, format, usedMem);
- RichString_append(out, CRT_colors[METER_TEXT], "used:");
+ Meter_humanUnit(buffer, this->values[0], 50);
+ RichString_append(out, CRT_colors[METER_TEXT], " used:");
RichString_append(out, CRT_colors[MEMORY_USED], buffer);
- sprintf(buffer, format, buffersMem);
- RichString_append(out, CRT_colors[METER_TEXT], "buffers:");
+ Meter_humanUnit(buffer, this->values[1], 50);
+ RichString_append(out, CRT_colors[METER_TEXT], " buffers:");
RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer);
- sprintf(buffer, format, cachedMem);
- RichString_append(out, CRT_colors[METER_TEXT], "cache:");
+ Meter_humanUnit(buffer, this->values[2], 50);
+ RichString_append(out, CRT_colors[METER_TEXT], " cache:");
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer);
}
diff --git a/SwapMeter.c b/SwapMeter.c
index aaa5e93c..895ca0be 100644
--- a/SwapMeter.c
+++ b/SwapMeter.c
@@ -20,19 +20,10 @@ in the source distribution for its full text.
#include "Meter.h"
}*/
-#define KILOBYTE 1
-#define MEGABYTE 1024
-#define GIGABYTE 1048576
-
int SwapMeter_attributes[] = {
SWAP
};
-/* NOTE: Value is in kilobytes */
-static void SwapMeter_humanNumber(char* buffer, const long int* value) {
- sprintf(buffer, "%ldM ", *value / MEGABYTE);
-}
-
static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
int written;
Platform_setSwapValues(this);
@@ -49,13 +40,11 @@ static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
static void SwapMeter_display(Object* cast, RichString* out) {
char buffer[50];
Meter* this = (Meter*)cast;
- long int swap = (long int) this->values[0];
- long int total = (long int) this->total;
RichString_write(out, CRT_colors[METER_TEXT], ":");
- SwapMeter_humanNumber(buffer, &total);
+ Meter_humanUnit(buffer, this->total, 50);
RichString_append(out, CRT_colors[METER_VALUE], buffer);
- SwapMeter_humanNumber(buffer, &swap);
- RichString_append(out, CRT_colors[METER_TEXT], "used:");
+ Meter_humanUnit(buffer, this->values[0], 50);
+ RichString_append(out, CRT_colors[METER_TEXT], " used:");
RichString_append(out, CRT_colors[METER_VALUE], buffer);
}
diff --git a/SwapMeter.h b/SwapMeter.h
index bb46a38c..2b57fe54 100644
--- a/SwapMeter.h
+++ b/SwapMeter.h
@@ -11,13 +11,8 @@ in the source distribution for its full text.
#include "Meter.h"
-#define KILOBYTE 1
-#define MEGABYTE 1024
-#define GIGABYTE 1048576
-
extern int SwapMeter_attributes[];
-/* NOTE: Value is in kilobytes */
extern MeterClass SwapMeter_class;
#endif

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