aboutsummaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:27 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:27 +0200
commit283707c5e5bc436b78ea23bf5500cb6b16a01148 (patch)
treeb977131bbbb4c3bd8ade370aab2e4fc913440c04 /Meter.c
parentbea9b4798717b6f4e31085506dfc179eeb8dc17c (diff)
downloaddebian_htop-283707c5e5bc436b78ea23bf5500cb6b16a01148.tar.gz
debian_htop-283707c5e5bc436b78ea23bf5500cb6b16a01148.tar.bz2
debian_htop-283707c5e5bc436b78ea23bf5500cb6b16a01148.zip
Imported Upstream version 0.9upstream/0.9
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/Meter.c b/Meter.c
index 9c32d35..341be72 100644
--- a/Meter.c
+++ b/Meter.c
@@ -1,6 +1,6 @@
/*
htop - Meter.c
-(C) 2004-2006 Hisham H. Muhammad
+(C) 2004-2010 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
@@ -42,7 +42,7 @@ typedef void(*Meter_Draw)(Meter*, int, int, int);
struct MeterMode_ {
Meter_Draw draw;
- char* uiName;
+ const char* uiName;
int h;
};
@@ -53,9 +53,9 @@ struct MeterType_ {
int items;
double total;
int* attributes;
- char* name;
- char* uiName;
- char* caption;
+ const char* name;
+ const char* uiName;
+ const char* caption;
MeterType_Init init;
MeterType_Done done;
MeterType_SetMode setMode;
@@ -128,8 +128,6 @@ MeterType* Meter_types[] = {
NULL
};
-static RichString Meter_stringBuffer;
-
Meter* Meter_new(ProcessList* pl, int param, MeterType* type) {
Meter* this = calloc(sizeof(Meter), 1);
Object_setClass(this, METER_CLASS);
@@ -161,19 +159,18 @@ void Meter_delete(Object* cast) {
free(this);
}
-void Meter_setCaption(Meter* this, char* caption) {
+void Meter_setCaption(Meter* this, const char* caption) {
free(this->caption);
this->caption = strdup(caption);
}
-static inline void Meter_displayToStringBuffer(Meter* this, char* buffer) {
+static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) {
MeterType* type = this->type;
Object_Display display = ((Object*)this)->display;
if (display) {
- display((Object*)this, &Meter_stringBuffer);
+ display((Object*)this, out);
} else {
- RichString_initVal(Meter_stringBuffer);
- RichString_append(&Meter_stringBuffer, CRT_colors[type->attributes[0]], buffer);
+ RichString_write(out, CRT_colors[type->attributes[0]], buffer);
}
}
@@ -229,10 +226,12 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
int captionLen = strlen(this->caption);
w -= captionLen;
x += captionLen;
- Meter_displayToStringBuffer(this, buffer);
mvhline(y, x, ' ', CRT_colors[DEFAULT_COLOR]);
attrset(CRT_colors[RESET_COLOR]);
- RichString_printVal(Meter_stringBuffer, y, x);
+ RichString_begin(out);
+ Meter_displayBuffer(this, buffer, &out);
+ RichString_printVal(out, y, x);
+ RichString_end(out);
}
/* ---------- BarMeterMode ---------- */
@@ -325,7 +324,7 @@ static int GraphMeterMode_colors[21] = {
GRAPH_8, GRAPH_8, GRAPH_9
};
-static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
+static const char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
@@ -345,15 +344,15 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
value /= this->total;
drawBuffer[METER_BUFFER_LEN - 1] = value;
for (int i = METER_BUFFER_LEN - w, k = 0; i < METER_BUFFER_LEN; i++, k++) {
- double value = drawBuffer[i];
+ value = drawBuffer[i];
DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' );
DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' );
DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' );
double threshold = 1.00;
- for (int i = 0; i < 21; i++, threshold -= 0.05)
+ for (int j = 0; j < 21; j++, threshold -= 0.05)
if (value >= threshold) {
- DrawDot(CRT_colors[GraphMeterMode_colors[i]], y+(i/7.0), GraphMeterMode_characters[i]);
+ DrawDot(CRT_colors[GraphMeterMode_colors[j]], y+(j/7.0), GraphMeterMode_characters[j]);
break;
}
}
@@ -362,7 +361,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
/* ---------- LEDMeterMode ---------- */
-static char* LEDMeterMode_digits[3][10] = {
+static const char* LEDMeterMode_digits[3][10] = {
{ " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ "},
{ "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|"},
{ "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|"},
@@ -374,17 +373,20 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) {
}
static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
+ (void) w;
MeterType* type = this->type;
char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1);
-
- Meter_displayToStringBuffer(this, buffer);
+
+ RichString_begin(out);
+ Meter_displayBuffer(this, buffer, &out);
attrset(CRT_colors[LED_COLOR]);
mvaddstr(y+2, x, this->caption);
int xx = x + strlen(this->caption);
- for (int i = 0; i < Meter_stringBuffer.len; i++) {
- char c = RichString_getCharVal(Meter_stringBuffer, i);
+ int len = RichString_sizeVal(out);
+ for (int i = 0; i < len; i++) {
+ char c = RichString_getCharVal(out, i);
if (c >= '0' && c <= '9') {
LEDMeterMode_drawDigit(xx, y, c-48);
xx += 4;
@@ -394,6 +396,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
}
}
attrset(CRT_colors[RESET_COLOR]);
+ RichString_end(out);
}
#endif

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