From cf47f4fca1bab93b81a2fb32cb548cb1722bb0f4 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 12 Jun 2015 09:53:18 +0200 Subject: use dynamic units for text display Signed-off-by: Christian Hesse --- SwapMeter.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'SwapMeter.c') 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); } -- cgit v1.2.3