Skip to content

Commit

Permalink
Refactor TUI panels and fix several memleaks (#4452)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah authored Apr 27, 2024
1 parent a7a29f1 commit 3aaa1bf
Show file tree
Hide file tree
Showing 6 changed files with 1,050 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion librz/core/cmd/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ RZ_IPI int rz_cmd_panels(void *data, const char *input) {
char *sp = strchr(input, ' ');
switch (input[0]) {
case ' ': // "v [name]"
if (visual->panels) {
if (visual->panels_root->active_tab) {
rz_load_panels_layout(core, input + 1);
}
rz_config_set(core->config, "scr.layout", input + 1);
Expand Down
2 changes: 1 addition & 1 deletion librz/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ RZ_API void rz_core_fini(RzCore *c) {
rz_core_seek_free(c);
RZ_FREE(c->rtr_host);
RZ_FREE(c->curtheme);
rz_core_visual_free(c->visual);
RZ_FREE_CUSTOM(c->visual, rz_core_visual_free);
}

RZ_API void rz_core_free(RzCore *c) {
Expand Down
21 changes: 11 additions & 10 deletions librz/core/core_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ typedef struct rz_core_visual_tab_t {

typedef int (*RzPanelsMenuCallback)(void *user);
typedef struct rz_panels_menu_item {
int n_sub, selectedIndex;
int selectedIndex;
char *name;
struct rz_panels_menu_item **sub;
RzPVector /*<RzPanelsMenuItem *>*/ submenus;
RzPanelsMenuCallback cb;
RzPanel *p;
} RzPanelsMenuItem;
Expand All @@ -295,7 +295,7 @@ typedef enum {
PANEL_LAYOUT_DEFAULT_DYNAMIC = 1
} RzPanelsLayout;

typedef struct rz_panels_t {
typedef struct rz_panels_tab_t {
RzConsCanvas *can;
RzPanel **panel;
int n_panels;
Expand All @@ -316,7 +316,7 @@ typedef struct rz_panels_t {
RzPanelsLayout layout;
char *name;
bool first_run;
} RzPanels;
} RzPanelsTab;

typedef enum {
DEFAULT,
Expand All @@ -326,12 +326,12 @@ typedef enum {
} RzPanelsRootState;

typedef struct rz_panels_root_t {
int n_panels;
int cur_panels;
Sdb *pdc_caches;
Sdb *cur_pdc_cache;
RzPanels **panels;
int cur_tab;
RzPVector /*<RzPanelsTab *>*/ tabs;
RzPanelsTab *active_tab; // Seems redudant since we have cur_tab index
RzPanelsRootState root_state;
RzList /*<char *>*/ *theme_list; ///< List of themes
bool from_visual;
} RzPanelsRoot;

typedef struct rz_core_visual_t {
Expand Down Expand Up @@ -363,12 +363,13 @@ typedef struct rz_core_visual_t {
int current5format;
/* Panels */
RzPanelsRoot *panels_root;
RzPanels *panels;
} RzCoreVisual;

RZ_IPI RZ_OWN RzCoreVisual *rz_core_visual_new();
RZ_IPI void rz_core_visual_free(RZ_NULLABLE RzCoreVisual *visual);

RZ_IPI void rz_panels_root_free(RZ_NULLABLE RzPanelsRoot *panels_root);

RZ_IPI void rz_core_visual_prompt_input(RzCore *core);
RZ_IPI void rz_core_visual_toggle_hints(RzCore *core);
RZ_IPI void rz_core_visual_toggle_decompiler_disasm(RzCore *core, bool for_graph, bool reset);
Expand Down
Loading

0 comments on commit 3aaa1bf

Please sign in to comment.