mirror of https://github.com/xzeldon/htop.git
Decouple Header from Meter classes.
(Yes, that's dynamic typing!)
This commit is contained in:
parent
cda6bdd56b
commit
b192af006f
26
Header.c
26
Header.c
|
@ -8,15 +8,6 @@ in the source distribution for its full text.
|
||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
|
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "CPUMeter.h"
|
|
||||||
#include "MemoryMeter.h"
|
|
||||||
#include "SwapMeter.h"
|
|
||||||
#include "TasksMeter.h"
|
|
||||||
#include "LoadAverageMeter.h"
|
|
||||||
#include "UptimeMeter.h"
|
|
||||||
#include "BatteryMeter.h"
|
|
||||||
#include "ClockMeter.h"
|
|
||||||
#include "HostnameMeter.h"
|
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -138,23 +129,6 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
|
||||||
return meter->mode;
|
return meter->mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Header_defaultMeters(Header* this, int cpuCount) {
|
|
||||||
if (cpuCount > 8) {
|
|
||||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUs2Meter)));
|
|
||||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUs2Meter)));
|
|
||||||
} else if (cpuCount > 4) {
|
|
||||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUsMeter)));
|
|
||||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUsMeter)));
|
|
||||||
} else {
|
|
||||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(AllCPUsMeter)));
|
|
||||||
}
|
|
||||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(MemoryMeter)));
|
|
||||||
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(SwapMeter)));
|
|
||||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(TasksMeter)));
|
|
||||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LoadAverageMeter)));
|
|
||||||
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(UptimeMeter)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Header_reinit(Header* this) {
|
void Header_reinit(Header* this) {
|
||||||
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
|
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
|
||||||
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
|
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
|
||||||
|
|
2
Header.h
2
Header.h
|
@ -47,8 +47,6 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side);
|
||||||
|
|
||||||
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side);
|
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side);
|
||||||
|
|
||||||
void Header_defaultMeters(Header* this, int cpuCount);
|
|
||||||
|
|
||||||
void Header_reinit(Header* this);
|
void Header_reinit(Header* this);
|
||||||
|
|
||||||
void Header_draw(const Header* this);
|
void Header_draw(const Header* this);
|
||||||
|
|
21
Settings.c
21
Settings.c
|
@ -61,6 +61,23 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
|
||||||
String_freeArray(ids);
|
String_freeArray(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Settings_defaultMeters(Header* header, int cpuCount) {
|
||||||
|
if (cpuCount > 8) {
|
||||||
|
Header_createMeter(header, "LeftCPUs2", LEFT_HEADER);
|
||||||
|
Header_createMeter(header, "RightCPUs2", RIGHT_HEADER);
|
||||||
|
} else if (cpuCount > 4) {
|
||||||
|
Header_createMeter(header, "LeftCPUs", LEFT_HEADER);
|
||||||
|
Header_createMeter(header, "RightCPUs", RIGHT_HEADER);
|
||||||
|
} else {
|
||||||
|
Header_createMeter(header, "AllCPUs", LEFT_HEADER);
|
||||||
|
}
|
||||||
|
Header_createMeter(header, "Memory", LEFT_HEADER);
|
||||||
|
Header_createMeter(header, "Swap", LEFT_HEADER);
|
||||||
|
Header_createMeter(header, "Tasks", RIGHT_HEADER);
|
||||||
|
Header_createMeter(header, "LoadAverage", RIGHT_HEADER);
|
||||||
|
Header_createMeter(header, "Uptime", RIGHT_HEADER);
|
||||||
|
}
|
||||||
|
|
||||||
static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
|
static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
|
||||||
FILE* fd = fopen(fileName, "r");
|
FILE* fd = fopen(fileName, "r");
|
||||||
if (!fd)
|
if (!fd)
|
||||||
|
@ -153,7 +170,7 @@ static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (!readMeters) {
|
if (!readMeters) {
|
||||||
Header_defaultMeters(this->header, cpuCount);
|
Settings_defaultMeters(this->header, cpuCount);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +290,7 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
|
||||||
ok = Settings_read(this, systemSettings, cpuCount);
|
ok = Settings_read(this, systemSettings, cpuCount);
|
||||||
free(systemSettings);
|
free(systemSettings);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
Header_defaultMeters(this->header, cpuCount);
|
Settings_defaultMeters(this->header, cpuCount);
|
||||||
pl->hideKernelThreads = true;
|
pl->hideKernelThreads = true;
|
||||||
pl->highlightMegabytes = true;
|
pl->highlightMegabytes = true;
|
||||||
pl->highlightThreads = false;
|
pl->highlightThreads = false;
|
||||||
|
|
Loading…
Reference in New Issue