use dynamic units for text display

Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Christian Hesse 2015-06-12 09:53:18 +02:00
parent 6f58fbc5dd
commit cf47f4fca1
3 changed files with 10 additions and 31 deletions

View File

@ -40,21 +40,16 @@ static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
static void MemoryMeter_display(Object* cast, RichString* out) { static void MemoryMeter_display(Object* cast, RichString* out) {
char buffer[50]; char buffer[50];
Meter* this = (Meter*)cast; 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], ":"); 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); RichString_append(out, CRT_colors[METER_VALUE], buffer);
sprintf(buffer, format, usedMem); Meter_humanUnit(buffer, this->values[0], 50);
RichString_append(out, CRT_colors[METER_TEXT], " used:"); RichString_append(out, CRT_colors[METER_TEXT], " used:");
RichString_append(out, CRT_colors[MEMORY_USED], buffer); RichString_append(out, CRT_colors[MEMORY_USED], buffer);
sprintf(buffer, format, buffersMem); Meter_humanUnit(buffer, this->values[1], 50);
RichString_append(out, CRT_colors[METER_TEXT], " buffers:"); RichString_append(out, CRT_colors[METER_TEXT], " buffers:");
RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer); RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer);
sprintf(buffer, format, cachedMem); Meter_humanUnit(buffer, this->values[2], 50);
RichString_append(out, CRT_colors[METER_TEXT], " cache:"); RichString_append(out, CRT_colors[METER_TEXT], " cache:");
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); RichString_append(out, CRT_colors[MEMORY_CACHE], buffer);
} }

View File

@ -20,19 +20,10 @@ in the source distribution for its full text.
#include "Meter.h" #include "Meter.h"
}*/ }*/
#define KILOBYTE 1
#define MEGABYTE 1024
#define GIGABYTE 1048576
int SwapMeter_attributes[] = { int SwapMeter_attributes[] = {
SWAP 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) { static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
int written; int written;
Platform_setSwapValues(this); Platform_setSwapValues(this);
@ -49,12 +40,10 @@ static void SwapMeter_setValues(Meter* this, char* buffer, int size) {
static void SwapMeter_display(Object* cast, RichString* out) { static void SwapMeter_display(Object* cast, RichString* out) {
char buffer[50]; char buffer[50];
Meter* this = (Meter*)cast; 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], ":"); 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); RichString_append(out, CRT_colors[METER_VALUE], buffer);
SwapMeter_humanNumber(buffer, &swap); Meter_humanUnit(buffer, this->values[0], 50);
RichString_append(out, CRT_colors[METER_TEXT], " used:"); RichString_append(out, CRT_colors[METER_TEXT], " used:");
RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_VALUE], buffer);
} }

View File

@ -11,13 +11,8 @@ in the source distribution for its full text.
#include "Meter.h" #include "Meter.h"
#define KILOBYTE 1
#define MEGABYTE 1024
#define GIGABYTE 1048576
extern int SwapMeter_attributes[]; extern int SwapMeter_attributes[];
/* NOTE: Value is in kilobytes */
extern MeterClass SwapMeter_class; extern MeterClass SwapMeter_class;
#endif #endif