diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
commit | 52e25213825024b8bb446eb26b03bedc9d5c2103 (patch) | |
tree | da70bf44b2423f6f8e9a070c063fed79d190b489 /ColorsPanel.c | |
parent | Initial commit. (diff) | |
download | htop-52e25213825024b8bb446eb26b03bedc9d5c2103.tar.xz htop-52e25213825024b8bb446eb26b03bedc9d5c2103.zip |
Adding upstream version 3.2.2.upstream/3.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ColorsPanel.c')
-rw-r--r-- | ColorsPanel.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/ColorsPanel.c b/ColorsPanel.c new file mode 100644 index 0000000..5900884 --- /dev/null +++ b/ColorsPanel.c @@ -0,0 +1,106 @@ +/* +htop - ColorsPanel.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "ColorsPanel.h" + +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> + +#include "CRT.h" +#include "FunctionBar.h" +#include "Macros.h" +#include "Object.h" +#include "OptionItem.h" +#include "ProvideCurses.h" + + +// TO ADD A NEW SCHEME: +// * Increment the size of bool check in ColorsPanel.h +// * Add the entry in the ColorSchemeNames array below in the file +// * Add a define in CRT.h that matches the order of the array +// * Add the colors in CRT_setColors + + +static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; + +static const char* const ColorSchemeNames[] = { + "Default", + "Monochromatic", + "Black on White", + "Light Terminal", + "MC", + "Black Night", + "Broken Gray", + NULL +}; + +static void ColorsPanel_delete(Object* object) { + Panel* super = (Panel*) object; + ColorsPanel* this = (ColorsPanel*) object; + Panel_done(super); + free(this); +} + +static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { + ColorsPanel* this = (ColorsPanel*) super; + + HandlerResult result = IGNORED; + int mark; + + switch (ch) { + case 0x0a: + case 0x0d: + case KEY_ENTER: + case KEY_MOUSE: + case KEY_RECLICK: + case ' ': + mark = Panel_getSelectedIndex(super); + assert(mark >= 0); + assert(mark < LAST_COLORSCHEME); + for (int i = 0; ColorSchemeNames[i] != NULL; i++) + CheckItem_set((CheckItem*)Panel_get(super, i), false); + CheckItem_set((CheckItem*)Panel_get(super, mark), true); + + this->settings->colorScheme = mark; + this->settings->changed = true; + this->settings->lastUpdate++; + + CRT_setColors(mark); + clear(); + + result = HANDLED | REDRAW; + } + + return result; +} + +const PanelClass ColorsPanel_class = { + .super = { + .extends = Class(Panel), + .delete = ColorsPanel_delete + }, + .eventHandler = ColorsPanel_eventHandler +}; + +ColorsPanel* ColorsPanel_new(Settings* settings) { + ColorsPanel* this = AllocThis(ColorsPanel); + Panel* super = (Panel*) this; + FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL); + Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); + + this->settings = settings; + + assert(ARRAYSIZE(ColorSchemeNames) == LAST_COLORSCHEME + 1); + + Panel_setHeader(super, "Colors"); + for (int i = 0; ColorSchemeNames[i] != NULL; i++) { + Panel_add(super, (Object*) CheckItem_newByVal(ColorSchemeNames[i], false)); + } + CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); + return this; +} |