aboutsummaryrefslogtreecommitdiffstats
path: root/TasksMeter.c
blob: 86bda9b275579c229824d708650e561c7562a489 (plain) (blame)
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
55
56
/*
htop
(C) 2004 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"

/*{

typedef struct TasksMeter_ TasksMeter;

struct TasksMeter_ {
   Meter super;
   ProcessList* pl;
};

}*/

TasksMeter* TasksMeter_new(ProcessList* pl) {
   TasksMeter* this = malloc(sizeof(TasksMeter));
   Meter_init((Meter*)this, String_copy("Tasks"), String_copy("Tasks: "), 1);
   ((Meter*)this)->attributes[0] = TASKS_RUNNING;
   ((Object*)this)->display = TasksMeter_display;
   ((Meter*)this)->setValues = TasksMeter_setValues;
   this->pl = pl;
   Meter_setMode((Meter*)this, TEXT);
   return this;
}

void TasksMeter_setValues(Meter* cast) {
   TasksMeter* this = (TasksMeter*)cast;
   cast->total = this->pl->totalTasks;
   cast->values[0] = this->pl->runningTasks;
   snprintf(cast->displayBuffer.c, 20, "%d/%d", (int) cast->values[0], (int) cast->total);
}

void TasksMeter_display(Object* cast, RichString* out) {
   Meter* this = (Meter*)cast;
   RichString_prune(out);
   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");
}

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