mirror of https://github.com/xzeldon/htop.git
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 {
|
typedef struct {
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
const char* name;
|
const char* name;
|
||||||
|
bool found;
|
||||||
} DynamicIterator;
|
} DynamicIterator;
|
||||||
|
|
||||||
static void DynamicMeter_compare(ht_key_t key, void* value, void* data) {
|
static void DynamicMeter_compare(ht_key_t key, void* value, void* data) {
|
||||||
const DynamicMeter* meter = (const DynamicMeter*)value;
|
const DynamicMeter* meter = (const DynamicMeter*)value;
|
||||||
DynamicIterator* iter = (DynamicIterator*)data;
|
DynamicIterator* iter = (DynamicIterator*)data;
|
||||||
if (String_eq(iter->name, meter->name))
|
if (String_eq(iter->name, meter->name)) {
|
||||||
|
iter->found = true;
|
||||||
iter->key = key;
|
iter->key = key;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int DynamicMeter_search(const ProcessList* pl, const char* name) {
|
bool DynamicMeter_search(const ProcessList* pl, const char* name, unsigned int* key) {
|
||||||
DynamicIterator iter = { .key = 0, .name = name };
|
DynamicIterator iter = { .key = 0, .name = name, .found = false };
|
||||||
if (pl->dynamicMeters)
|
if (pl->dynamicMeters)
|
||||||
Hashtable_foreach(pl->dynamicMeters, DynamicMeter_compare, &iter);
|
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) {
|
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);
|
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;
|
extern const MeterClass DynamicMeter_class;
|
||||||
|
|
||||||
|
|
20
Header.c
20
Header.c
|
@ -46,7 +46,9 @@ void Header_populateFromSettings(Header* this) {
|
||||||
Header_forEachColumn(this, col) {
|
Header_forEachColumn(this, col) {
|
||||||
const MeterColumnSettings* colSettings = &this->settings->columns[col];
|
const MeterColumnSettings* colSettings = &this->settings->columns[col];
|
||||||
for (int i = 0; i < colSettings->len; i++) {
|
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) {
|
if (colSettings->modes[i] != 0) {
|
||||||
Header_setMode(this, i, colSettings->modes[i], col);
|
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];
|
Vector* meters = this->columns[column];
|
||||||
|
|
||||||
char* paren = strchr(name, '(');
|
char* paren = strchr(name, '(');
|
||||||
|
@ -95,18 +97,20 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
|
||||||
char* end, dynamic[32] = {0};
|
char* end, dynamic[32] = {0};
|
||||||
int ok = sscanf(paren, "(%10u)", ¶m); // CPUMeter
|
int ok = sscanf(paren, "(%10u)", ¶m); // CPUMeter
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
ok = sscanf(paren, "(%30s)", dynamic); // DynamicMeter
|
if (sscanf(paren, "(%30s)", dynamic)) { // DynamicMeter
|
||||||
if (ok && (end = strrchr(dynamic, ')'))) *end = '\0';
|
if ((end = strrchr(dynamic, ')')) == NULL)
|
||||||
param = ok ? DynamicMeter_search(this->pl, dynamic) : 0;
|
return false; // indicate htoprc parse failure
|
||||||
|
*end = '\0';
|
||||||
|
if (!DynamicMeter_search(this->pl, dynamic, ¶m))
|
||||||
|
return false; // indicates name lookup failure
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*paren = '\0';
|
*paren = '\0';
|
||||||
}
|
}
|
||||||
MeterModeId mode = TEXT_METERMODE;
|
|
||||||
for (const MeterClass* const* type = Platform_meterTypes; *type; type++) {
|
for (const MeterClass* const* type = Platform_meterTypes; *type; type++) {
|
||||||
if (String_eq(name, (*type)->name)) {
|
if (String_eq(name, (*type)->name)) {
|
||||||
Meter* meter = Meter_new(this->pl, param, *type);
|
Meter* meter = Meter_new(this->pl, param, *type);
|
||||||
Vector_add(meters, meter);
|
Vector_add(meters, meter);
|
||||||
mode = meter->mode;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +118,7 @@ MeterModeId Header_addMeterByName(Header* this, const char* name, int column) {
|
||||||
if (paren)
|
if (paren)
|
||||||
*paren = '(';
|
*paren = '(';
|
||||||
|
|
||||||
return mode;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
|
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);
|
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);
|
void Header_setMode(Header* this, int i, MeterModeId mode, int column);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue