From 999801464a8a4d818e2ee3c87855a66929538a62 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Wed, 4 May 2022 21:26:33 +0200 Subject: [PATCH] Add some headers in the Setup -> Display options panel --- DisplayOptionsPanel.c | 13 ++++++++++++- OptionItem.c | 24 ++++++++++++++++++++++++ OptionItem.h | 10 ++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index f5e64b13..7688e7c7 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -18,6 +18,7 @@ in the source distribution for its full text. #include "Object.h" #include "OptionItem.h" #include "ProvideCurses.h" +#include "ScreensPanel.h" static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; @@ -43,6 +44,8 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { case KEY_RECLICK: case ' ': switch (OptionItem_kind(selected)) { + case OPTION_ITEM_TEXT: + break; case OPTION_ITEM_CHECK: CheckItem_toggle((CheckItem*)selected); result = HANDLED; @@ -97,9 +100,17 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* this->scr = scr; Panel_setHeader(super, "Display options"); - Panel_add(super, (Object*) CheckItem_newByRef("Tree view (for the current Screen tab)", &(settings->ss->treeView))); + + #define TABMSG "For current screen tab: \0" + char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG; + strncat(tabheader, settings->ss->name, SCREEN_NAME_LEN); + Panel_add(super, (Object*) TextItem_new(tabheader)); + #undef TABMSG + + Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView))); Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID))); Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed))); + Panel_add(super, (Object*) TextItem_new("Global options:")); Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs))); Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers))); Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads))); diff --git a/OptionItem.c b/OptionItem.c index 7ab69002..962c0a9c 100644 --- a/OptionItem.c +++ b/OptionItem.c @@ -25,6 +25,13 @@ static void OptionItem_delete(Object* cast) { free(this); } +static void TextItem_display(const Object* cast, RichString* out) { + const TextItem* this = (const TextItem*)cast; + assert (this != NULL); + + RichString_appendWide(out, CRT_colors[HELP_BOLD], this->super.text); +} + static void CheckItem_display(const Object* cast, RichString* out) { const CheckItem* this = (const CheckItem*)cast; assert (this != NULL); @@ -68,6 +75,16 @@ const OptionItemClass OptionItem_class = { } }; +const OptionItemClass TextItem_class = { + .super = { + .extends = Class(OptionItem), + .delete = OptionItem_delete, + .display = TextItem_display + }, + .kind = OPTION_ITEM_TEXT +}; + + const OptionItemClass CheckItem_class = { .super = { .extends = Class(OptionItem), @@ -77,6 +94,7 @@ const OptionItemClass CheckItem_class = { .kind = OPTION_ITEM_CHECK }; + const OptionItemClass NumberItem_class = { .super = { .extends = Class(OptionItem), @@ -86,6 +104,12 @@ const OptionItemClass NumberItem_class = { .kind = OPTION_ITEM_NUMBER }; +TextItem* TextItem_new(const char* text) { + TextItem* this = AllocThis(TextItem); + this->super.text = xStrdup(text); + return this; +} + CheckItem* CheckItem_newByRef(const char* text, bool* ref) { CheckItem* this = AllocThis(CheckItem); this->super.text = xStrdup(text); diff --git a/OptionItem.h b/OptionItem.h index 35c85062..ba28775d 100644 --- a/OptionItem.h +++ b/OptionItem.h @@ -13,6 +13,7 @@ in the source distribution for its full text. enum OptionItemType { + OPTION_ITEM_TEXT, OPTION_ITEM_CHECK, OPTION_ITEM_NUMBER, }; @@ -32,6 +33,12 @@ typedef struct OptionItem_ { char* text; } OptionItem; +typedef struct TextItem_ { + OptionItem super; + + char* text; +} TextItem; + typedef struct CheckItem_ { OptionItem super; @@ -51,9 +58,12 @@ typedef struct NumberItem_ { } NumberItem; extern const OptionItemClass OptionItem_class; +extern const OptionItemClass TextItem_class; extern const OptionItemClass CheckItem_class; extern const OptionItemClass NumberItem_class; +TextItem* TextItem_new(const char* text); + CheckItem* CheckItem_newByRef(const char* text, bool* ref); CheckItem* CheckItem_newByVal(const char* text, bool value); bool CheckItem_get(const CheckItem* this);