~ubuntu-branches/ubuntu/intrepid/htop/intrepid

« back to all changes in this revision

Viewing changes to TasksMeter.c

  • Committer: Bazaar Package Importer
  • Author(s): Bartosz Fenski
  • Date: 2004-11-27 10:10:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041127101017-vwknw2ipfvxchno4
Tags: 0.5-1
* New upstream version.
  - fixes problem with wrongly displayed CPU bar (Closes: #283212)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
htop
 
3
(C) 2004 Hisham H. Muhammad
 
4
Released under the GNU GPL, see the COPYING file
 
5
in the source distribution for its full text.
 
6
*/
 
7
 
 
8
#include "TasksMeter.h"
 
9
#include "Meter.h"
 
10
 
 
11
#include "ProcessList.h"
 
12
 
 
13
#include "CRT.h"
 
14
 
 
15
#include "debug.h"
 
16
 
 
17
/*{
 
18
 
 
19
typedef struct TasksMeter_ TasksMeter;
 
20
 
 
21
struct TasksMeter_ {
 
22
   Meter super;
 
23
   ProcessList* pl;
 
24
};
 
25
 
 
26
}*/
 
27
 
 
28
TasksMeter* TasksMeter_new(ProcessList* pl) {
 
29
   TasksMeter* this = malloc(sizeof(TasksMeter));
 
30
   Meter_init((Meter*)this, String_copy("Tasks"), String_copy("Tasks: "), 1);
 
31
   ((Meter*)this)->attributes[0] = CRT_colors[TASKS_RUNNING];
 
32
   ((Object*)this)->display = TasksMeter_display;
 
33
   ((Meter*)this)->setValues = TasksMeter_setValues;
 
34
   this->pl = pl;
 
35
   Meter_setMode((Meter*)this, TEXT);
 
36
   return this;
 
37
}
 
38
 
 
39
void TasksMeter_setValues(Meter* cast) {
 
40
   TasksMeter* this = (TasksMeter*)cast;
 
41
   cast->total = this->pl->totalTasks;
 
42
   cast->values[0] = this->pl->runningTasks;
 
43
   snprintf(cast->displayBuffer.c, 20, "%d/%d", (int) cast->values[0], (int) cast->total);
 
44
}
 
45
 
 
46
void TasksMeter_display(Object* cast, RichString* out) {
 
47
   Meter* this = (Meter*)cast;
 
48
   RichString_prune(out);
 
49
   char buffer[20];
 
50
   sprintf(buffer, "%d", (int)this->total);
 
51
   RichString_append(out, CRT_colors[METER_VALUE], buffer);
 
52
   RichString_append(out, CRT_colors[METER_TEXT], " total, ");
 
53
   sprintf(buffer, "%d", (int)this->values[0]);
 
54
   RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
 
55
   RichString_append(out, CRT_colors[METER_TEXT], " running");
 
56
}