TasksMeter.c 1.26 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
/*
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 "TasksMeter.h"
#include "Meter.h"

#include "ProcessList.h"

#include "CRT.h"

#include "debug.h"

17
18
19
int TasksMeter_attributes[] = {
   TASKS_RUNNING
};
20

21
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
22
23
24
   this->total = this->pl->totalTasks;
   this->values[0] = this->pl->runningTasks;
   snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
Hisham Muhammad's avatar
Hisham Muhammad committed
25
26
}

27
static void TasksMeter_display(Object* cast, RichString* out) {
Hisham Muhammad's avatar
Hisham Muhammad committed
28
   Meter* this = (Meter*)cast;
29
   RichString_init(out);
Hisham Muhammad's avatar
Hisham Muhammad committed
30
31
32
33
34
35
36
37
   char buffer[20];
   sprintf(buffer, "%d", (int)this->total);
   RichString_append(out, CRT_colors[METER_VALUE], buffer);
   RichString_append(out, CRT_colors[METER_TEXT], " total, ");
   sprintf(buffer, "%d", (int)this->values[0]);
   RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
   RichString_append(out, CRT_colors[METER_TEXT], " running");
}
38
39
40
41
42
43
44
45
46
47
48
49

MeterType TasksMeter = {
   .setValues = TasksMeter_setValues, 
   .display = TasksMeter_display,
   .mode = TEXT_METERMODE,
   .items = 1,
   .total = 100.0,
   .attributes = TasksMeter_attributes, 
   .name = "Tasks",
   .uiName = "Task counter",
   .caption = "Tasks: "
};