Skip to content

Commit

Permalink
Add some headers in the Setup -> Display options panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lange authored and BenBE committed May 27, 2022
1 parent 0e29174 commit 9998014
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
13 changes: 12 additions & 1 deletion DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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)));
Expand Down
24 changes: 24 additions & 0 deletions OptionItem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -77,6 +94,7 @@ const OptionItemClass CheckItem_class = {
.kind = OPTION_ITEM_CHECK
};


const OptionItemClass NumberItem_class = {
.super = {
.extends = Class(OptionItem),
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions OptionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in the source distribution for its full text.


enum OptionItemType {
OPTION_ITEM_TEXT,
OPTION_ITEM_CHECK,
OPTION_ITEM_NUMBER,
};
Expand All @@ -32,6 +33,12 @@ typedef struct OptionItem_ {
char* text;
} OptionItem;

typedef struct TextItem_ {
OptionItem super;

char* text;
} TextItem;

typedef struct CheckItem_ {
OptionItem super;

Expand All @@ -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);
Expand Down

0 comments on commit 9998014

Please sign in to comment.