From 955208569cc2ede37de15172fab8cdb7bfbe80fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Wed, 31 May 2023 14:17:10 +0200 Subject: Settings: preserve empty header If the user removes all meters from the header on exit htop will write no values for the settings column_meters_X and column_meter_modes_X. The parser skips all configuration settings with no value, so on the next start no header meter related key is processed and htop will add a set of default meters to the header. Write instead an invalid value of `!`, so the keys are parsed and htop will not add the default meters back. Closes: #1248 --- Settings.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Settings.c') diff --git a/Settings.c b/Settings.c index a7787d30..a01e2494 100644 --- a/Settings.c +++ b/Settings.c @@ -592,15 +592,25 @@ static void writeList(FILE* fd, char** list, int len, char separator) { } static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) { - writeList(fd, this->hColumns[column].names, this->hColumns[column].len, separator); + if (this->hColumns[column].len) { + writeList(fd, this->hColumns[column].names, this->hColumns[column].len, separator); + } else { + fputc('!', fd); + fputc(separator, fd); + } } static void writeMeterModes(const Settings* this, FILE* fd, char separator, unsigned int column) { - const char* sep = ""; - for (size_t i = 0; i < this->hColumns[column].len; i++) { - fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]); - sep = " "; + if (this->hColumns[column].len) { + const char* sep = ""; + for (size_t i = 0; i < this->hColumns[column].len; i++) { + fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]); + sep = " "; + } + } else { + fputc('!', fd); } + fputc(separator, fd); } -- cgit v1.2.3