mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Ensure we do not attempt to add a DynamicMeter via the
htoprc that we didn't find during start up. This just leaves blank sections of the display as @smalinux found. Related to https://github.com/htop-dev/htop/pull/682
This commit is contained in:
parent
bf22a8fb13
commit
a476490282
@ -36,20 +36,24 @@ Hashtable* DynamicMeters_new(void) {
|
||||
typedef struct {
|
||||
unsigned int key;
|
||||
const char* name;
|
||||
bool found;
|
||||
} DynamicIterator;
|
||||
|
||||
static void DynamicMeter_compare(ht_key_t key, void* value, void* data) {
|
||||
const DynamicMeter* meter = (const DynamicMeter*)value;
|
||||
DynamicIterator* iter = (DynamicIterator*)data;
|
||||
if (String_eq(iter->name, meter->name))
|
||||
if (String_eq(iter->name, meter->name)) {
|
||||
iter->found = true;
|
||||
iter->key = key;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int DynamicMeter_search(const ProcessList* pl, const char* name) {
|
||||
DynamicIterator iter = { .key = 0, .name = name };
|
||||
bool DynamicMeter_search(const ProcessList* pl, const char* name, unsigned int* key) {
|
||||
DynamicIterator iter = { .key = 0, .name = name, .found = false };
|
||||
if (pl->dynamicMeters)
|
||||
Hashtable_foreach(pl->dynamicMeters, DynamicMeter_compare, &iter);
|
||||
return iter.key;
|
||||
*key = iter.key;
|
||||
return iter.found;
|
||||
}
|
||||
|
||||
const char* DynamicMeter_lookup(const ProcessList* pl, unsigned int key) {
|
||||
|
@ -18,7 +18,7 @@ Hashtable* DynamicMeters_new(void);
|
||||
|
||||
const char* DynamicMeter_lookup(const ProcessList* pl, unsigned int param);
|
||||
|
||||
unsigned int DynamicMeter_search(const ProcessList* pl, const char* name);
|
||||
bool DynamicMeter_search(const ProcessList* pl, const char* name, unsigned int* key);
|
||||
|
||||
extern const MeterClass DynamicMeter_class;
|
||||
|
||||
|
20
Header.c
20
Header.c
@ -46,7 +46,9 @@ void Header_populateFromSettings(Header* this) {
|
||||
Header_forEachColumn(this, col) {
|
||||
const MeterColumnSettings* colSettings = &this->settings->columns[col];
|
||||
for (int i = 0; i < colSettings->len; i++) {
|
||||
Header_addMeterByName(this, colSettings->names[i], col);
|
||||
if (!Header_addMeterByName(this, colSettings->names[i], col)) {
|
||||
continue;
|
||||
}
|
||||
if (colSettings->modes[i] != 0) {
|
||||
Header_setMode(this, i, colSettings->modes[i], col);
|
||||
}
|
||||
@ -86,7 +88,7 @@ void Header_writeBackToSettings(const Header* this) {
|
||||
}
|
||||
}
|
||||
|
||||
MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
|
||||
bool Header_addMeterByName(Header* this, const char* name, int column) {
|
||||
Vector* meters = this->columns[column];
|
||||
|
||||
char* paren = strchr(name, '(');
|
||||
@ -95,18 +97,20 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
|
||||
char* end, dynamic[32] = {0};
|
||||
int ok = sscanf(paren, "(%10u)", ¶m); // CPUMeter
|
||||
if (!ok) {
|
||||
ok = sscanf(paren, "(%30s)", dynamic); // DynamicMeter
|
||||
if (ok && (end = strrchr(dynamic, ')'))) *end = '\0';
|
||||
param = ok ? DynamicMeter_search(this->pl, dynamic) : 0;
|
||||
if (sscanf(paren, "(%30s)", dynamic)) { // DynamicMeter
|
||||
if ((end = strrchr(dynamic, ')')) == NULL)
|
||||
return false; // indicate htoprc parse failure
|
||||
*end = '\0';
|
||||
if (!DynamicMeter_search(this->pl, dynamic, ¶m))
|
||||
return false; // indicates name lookup failure
|
||||
}
|
||||
}
|
||||
*paren = '\0';
|
||||
}
|
||||
MeterModeId mode = TEXT_METERMODE;
|
||||
for (const MeterClass* const* type = Platform_meterTypes; *type; type++) {
|
||||
if (String_eq(name, (*type)->name)) {
|
||||
Meter* meter = Meter_new(this->pl, param, *type);
|
||||
Vector_add(meters, meter);
|
||||
mode = meter->mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -114,7 +118,7 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
|
||||
if (paren)
|
||||
*paren = '(';
|
||||
|
||||
return mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
|
||||
|
2
Header.h
2
Header.h
@ -32,7 +32,7 @@ void Header_populateFromSettings(Header* this);
|
||||
|
||||
void Header_writeBackToSettings(const Header* this);
|
||||
|
||||
MeterModeId Header_addMeterByName(Header* this, const char* name, int column);
|
||||
bool Header_addMeterByName(Header* this, const char* name, int column);
|
||||
|
||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user