ClockMeter.c 1.27 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
htop
(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "ClockMeter.h"
#include "Meter.h"

#include "ProcessList.h"

#include <curses.h>
#include <time.h>

#include "debug.h"

/*{

typedef struct ClockMeter_ ClockMeter;

struct ClockMeter_ {
   Meter super;
   ProcessList* pl;
   char clock[10];
};

}*/

ClockMeter* ClockMeter_new() {
   ClockMeter* this = malloc(sizeof(ClockMeter));
   Meter_init((Meter*)this, String_copy("Clock"), String_copy("Time: "), 1);
   ((Meter*)this)->attributes[0] = CLOCK;
   ((Meter*)this)->setValues = ClockMeter_setValues;
   ((Object*)this)->display = ClockMeter_display;
   ((Meter*)this)->total = 24 * 60;
   Meter_setMode((Meter*)this, TEXT);
   return this;
}

void ClockMeter_setValues(Meter* cast) {
   ClockMeter* this = (ClockMeter*) cast;
   time_t t = time(NULL);
   struct tm *lt = localtime(&t);
   cast->values[0] = lt->tm_hour * 60 + lt->tm_min;
   strftime(this->clock, 9, "%H:%M:%S", lt);
   snprintf(cast->displayBuffer.c, 9, "%s", this->clock);
}

void ClockMeter_display(Object* cast, RichString* out) {
   Meter* super = (Meter*) cast;
   ClockMeter* this = (ClockMeter*) cast;
   RichString_write(out, CRT_colors[super->attributes[0]], this->clock);
}