mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 18:43:45 +00:00
More refactorings in visual panels
* bunch of refactoring and the split screen function has been added.
This commit is contained in:
parent
4b3b4d8059
commit
14ec1592a7
@ -37,6 +37,8 @@
|
||||
#define PANEL_CMD_DISASSEMBLY "pd $r"
|
||||
#define PANEL_CMD_GRAPH "agf"
|
||||
|
||||
#define PANEL_CONFIG_PAGE 10
|
||||
|
||||
static const int layoutMaxCount = 2;
|
||||
|
||||
enum {
|
||||
@ -108,6 +110,9 @@ static const char **menus_sub[] = {
|
||||
};
|
||||
|
||||
static void layoutMenu(RPanel *panel);
|
||||
static void layoutDefault(RPanels *panels);
|
||||
static void layoutBalance(RPanels *panels);
|
||||
static void splitPanel(RCore *core);
|
||||
static void panelPrint(RCore *core, RConsCanvas *can, RPanel *panel, int color);
|
||||
static void addPanelFrame(RCore* core, RPanels* panels, const char *title, const char *cmd);
|
||||
static bool checkFunc(RCore *core);
|
||||
@ -132,7 +137,6 @@ static void panelSingleStepOver(RCore *core);
|
||||
static void setRefreshAll(RPanels *panels);
|
||||
static void setCursor(RCore *core, bool cur);
|
||||
static void replaceCmd(RPanels* panels, char *title, char *cmd);
|
||||
static void zoom(RPanels *panels);
|
||||
|
||||
static void panelPrint(RCore *core, RConsCanvas *can, RPanel *panel, int color) {
|
||||
if (!can || !panel|| !panel->refresh) {
|
||||
@ -231,99 +235,106 @@ static void layoutMenu(RPanel *panel) {
|
||||
panel->h += 4;
|
||||
}
|
||||
|
||||
R_API void r_core_panels_layout(RPanels *panels) {
|
||||
int h, w = r_cons_get_size (&h);
|
||||
int i, j;
|
||||
int colpos = w - panels->columnWidth;
|
||||
RPanel *panel = panels->panel;
|
||||
|
||||
if (colpos < 0) {
|
||||
panels->columnWidth = w;
|
||||
colpos = 0;
|
||||
}
|
||||
R_API void r_core_panels_layout (RPanels *panels) {
|
||||
panels->can->sx = 0;
|
||||
panels->can->sy = 0;
|
||||
for (i = j = 0; i < panels->n_panels; i++) {
|
||||
switch (panel[i].type) {
|
||||
case PANEL_TYPE_MENU:
|
||||
layoutMenu (&panel[i]);
|
||||
layoutMenu (&panels->panel[panels->menu_pos]);
|
||||
switch (panels->layout) {
|
||||
case LAYOUT_DEFAULT:
|
||||
layoutDefault (panels);
|
||||
break;
|
||||
case PANEL_TYPE_FRAME:
|
||||
switch (panels->layout) {
|
||||
case LAYOUT_DEFAULT:
|
||||
if (j == 0) {
|
||||
panel[i].x = 0;
|
||||
panel[i].y = 1;
|
||||
if (panel[j + 1].title) {
|
||||
panel[i].w = colpos + 1;
|
||||
} else {
|
||||
panel[i].w = w;
|
||||
}
|
||||
panel[i].h = h - 1;
|
||||
} else {
|
||||
int ph = ((h - 1) / (panels->n_panels - 2));
|
||||
panel[i].x = colpos;
|
||||
panel[i].y = 1 + (ph * (j - 1));
|
||||
panel[i].w = w - colpos;
|
||||
if (panel[i].w < 0) {
|
||||
panel[i].w = 0;
|
||||
}
|
||||
panel[i].h = ph;
|
||||
if (!panel[i + 1].title) {
|
||||
panel[i].h = h - panel[i].y;
|
||||
}
|
||||
if (j != 1) {
|
||||
panel[i].y--;
|
||||
panel[i].h++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LAYOUT_BALANCE:
|
||||
if (j == 0) {
|
||||
panel[i].x = 0;
|
||||
panel[i].y = 1;
|
||||
if (panel[j + 1].title) {
|
||||
panel[i].w = colpos + 1;
|
||||
} else {
|
||||
panel[i].w = w;
|
||||
}
|
||||
panel[i].h = (h / 2) + 1;
|
||||
} else if (j == 1) {
|
||||
panel[i].x = 0;
|
||||
panel[i].y = (h / 2) + 1;
|
||||
if (panel[j + 1].title) {
|
||||
panel[i].w = colpos + 1;
|
||||
} else {
|
||||
panel[i].w = w;
|
||||
}
|
||||
panel[i].h = (h - 1) / 2;
|
||||
} else {
|
||||
int ph = ((h - 1) / (panels->n_panels - 3));
|
||||
panel[i].x = colpos;
|
||||
panel[i].y = 1 + (ph * (j - 2));
|
||||
panel[i].w = w - colpos;
|
||||
if (panel[i].w < 0) {
|
||||
panel[i].w = 0;
|
||||
}
|
||||
panel[i].h = ph;
|
||||
if (!panel[i + 1].title) {
|
||||
panel[i].h = h - panel[i].y;
|
||||
}
|
||||
if (j != 2) {
|
||||
panel[i].y--;
|
||||
panel[i].h++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
case LAYOUT_BALANCE:
|
||||
layoutBalance (panels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void layoutDefault(RPanels *panels) {
|
||||
int h, w = r_cons_get_size (&h);
|
||||
int ph = (h - 1) / (panels->n_panels - 2);
|
||||
int i;
|
||||
int colpos = w - panels->columnWidth;
|
||||
RPanel *panel = panels->panel;
|
||||
panel[1].x = 0;
|
||||
panel[1].y = 1;
|
||||
if (panels->n_panels > 2) {
|
||||
panel[1].w = colpos + 1;
|
||||
} else {
|
||||
panel[1].w = w;
|
||||
}
|
||||
panel[1].h = h - 1;
|
||||
for (i = 2; i < panels->n_panels; i++) {
|
||||
panel[i].x = colpos;
|
||||
panel[i].y = 2 + (ph * (i - 2));
|
||||
panel[i].w = w - colpos;
|
||||
if (panel[i].w < 0) {
|
||||
panel[i].w = 0;
|
||||
}
|
||||
if ((i + 1) == panels->n_panels) {
|
||||
panel[i].h = h - panel[i].y;
|
||||
} else {
|
||||
panel[i].h = ph;
|
||||
}
|
||||
panel[i].y--;
|
||||
panel[i].h++;
|
||||
}
|
||||
}
|
||||
|
||||
static void layoutBalance(RPanels *panels) {
|
||||
int h, w = r_cons_get_size (&h);
|
||||
int i, ii;
|
||||
int panelNum = panels->n_panels - 1;
|
||||
int leftCol = panelNum / 2;
|
||||
int rightCol = panelNum - leftCol;
|
||||
int pw = w / 2;
|
||||
RPanel *panel = panels->panel;
|
||||
for (i = 0; i < leftCol; i++) {
|
||||
ii = i + 1;
|
||||
panel[ii].x = 0;
|
||||
panel[ii].y = 1 + i * (h / leftCol - 1);
|
||||
panel[ii].w = pw + 2;
|
||||
panel[ii].h = h / leftCol;
|
||||
if (i == leftCol - 1) {
|
||||
panel[ii].h = h - panel[ii].y;
|
||||
} else {
|
||||
panel[ii].h = h / leftCol;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < rightCol; i++) {
|
||||
ii = i + 1 + leftCol;
|
||||
panel[ii].x = pw + 1;
|
||||
panel[ii].y = 1 + i * (h / rightCol - 1);
|
||||
panel[ii].w = pw - 1;
|
||||
if (i == rightCol - 1) {
|
||||
panel[ii].h = h - panel[ii].y;
|
||||
} else {
|
||||
panel[ii].h = h / rightCol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void splitPanel(RCore *core) {
|
||||
RPanels *panels = core->panels;
|
||||
RPanel *panel = panels->panel;
|
||||
int i;
|
||||
const int curnode = panels->curnode;
|
||||
|
||||
addPanelFrame (core, panels, panel[curnode].title, panel[curnode].cmd);
|
||||
RPanel tmpPanel = panel[panels->n_panels - 1];
|
||||
for (i = panels->n_panels - 1; i >= curnode + 2; i--) {
|
||||
panel[i] = panel[i - 1];
|
||||
}
|
||||
panel[curnode + 1] = tmpPanel;
|
||||
panel[curnode].w = panel[curnode].w / 2 + 1;
|
||||
panel[curnode + 1].x = panel[curnode].x + panel[curnode].w - 1;
|
||||
panel[curnode + 1].y = panel[curnode].y;
|
||||
panel[curnode + 1].w = panel[curnode].w - 1;
|
||||
panel[curnode + 1].h = panel[curnode].h;
|
||||
setRefreshAll (panels);
|
||||
}
|
||||
|
||||
R_API void r_core_panels_layout_refresh(RCore *core) {
|
||||
r_core_panels_check_stackbase (core);
|
||||
r_core_panels_layout (core->panels);
|
||||
r_core_panels_refresh (core);
|
||||
}
|
||||
|
||||
@ -550,18 +561,6 @@ static void replaceCmd(RPanels* panels, char *title, char *cmd) {
|
||||
setRefreshAll (panels);
|
||||
}
|
||||
|
||||
static void zoom(RPanels *panels) {
|
||||
if (panels->n_panels > 2) {
|
||||
if (panels->curnode < 2) {
|
||||
panels->curnode = 2;
|
||||
}
|
||||
RPanel ocurnode = panels->panel[panels->curnode];
|
||||
panels->panel[panels->curnode] = panels->panel[1];
|
||||
panels->panel[1] = ocurnode;
|
||||
panels->curnode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool checkFunc(RCore *core) {
|
||||
RAnalFunction *fun = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL);
|
||||
if (!fun) {
|
||||
@ -602,8 +601,6 @@ static void addPanelFrame(RCore *core, RPanels* panels, const char *title, const
|
||||
panel[panels->n_panels].addr = stackbase - r_config_get_i (core->config, "stack.delta");
|
||||
}
|
||||
panels->n_panels++;
|
||||
panels->curnode = panels->n_panels - 1;
|
||||
zoom (panels);
|
||||
panels->menu_y = 0;
|
||||
}
|
||||
|
||||
@ -617,11 +614,11 @@ static bool initPanels(RCore *core, RPanels *panels) {
|
||||
panels->panel[panels->n_panels].refresh = true;
|
||||
panels->n_panels++;
|
||||
|
||||
addPanelFrame (core, panels, PANEL_TITLE_DISASSEMBLY, PANEL_CMD_DISASSEMBLY);
|
||||
addPanelFrame (core, panels, PANEL_TITLE_SYMBOLS, PANEL_CMD_SYMBOLS);
|
||||
addPanelFrame (core, panels, PANEL_TITLE_STACK, PANEL_CMD_STACK);
|
||||
addPanelFrame (core, panels, PANEL_TITLE_REGISTERS, PANEL_CMD_REGISTERS);
|
||||
addPanelFrame (core, panels, PANEL_TITLE_REGISTERREFS, PANEL_CMD_REGISTERREFS);
|
||||
addPanelFrame (core, panels, PANEL_TITLE_DISASSEMBLY, PANEL_CMD_DISASSEMBLY);
|
||||
panels->curnode = 1;
|
||||
return true;
|
||||
}
|
||||
@ -1035,12 +1032,8 @@ static bool handleEnterKey(RCore *core) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (panels->curnode > 0) {
|
||||
zoom (panels);
|
||||
} else {
|
||||
panels->curnode = panels->menu_pos;
|
||||
panels->menu_y = 1;
|
||||
}
|
||||
panels->curnode = panels->menu_pos;
|
||||
panels->menu_y = 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1098,6 +1091,7 @@ R_API int r_core_visual_panels(RCore *core, RPanels *panels) {
|
||||
core->print->cur_enabled = false;
|
||||
core->print->col = 0;
|
||||
|
||||
r_core_panels_layout (panels);
|
||||
repeat:
|
||||
core->panels = panels;
|
||||
core->cons->event_data = core;
|
||||
@ -1164,7 +1158,7 @@ repeat:
|
||||
} else {
|
||||
r_core_cmd0 (core, "s entry0; px");
|
||||
}
|
||||
doPanelsRefresh (core);
|
||||
setRefreshAll (panels);
|
||||
break;
|
||||
case ' ':
|
||||
case '\r':
|
||||
@ -1228,7 +1222,7 @@ repeat:
|
||||
// FIX: Issue with visual mode instruction highlighter
|
||||
// not updating after 'ds' or 'dcu' commands.
|
||||
r_core_cmd0 (core, ".dr*");
|
||||
doPanelsRefresh (core);
|
||||
setRefreshAll (panels);
|
||||
break;
|
||||
case 'c':
|
||||
if (!strcmp (panels->panel[panels->curnode].title, PANEL_TITLE_STACK) || !strcmp (panels->panel[panels->curnode].title, PANEL_TITLE_REGISTERS)) {
|
||||
@ -1240,7 +1234,7 @@ repeat:
|
||||
can->color = !can->color;
|
||||
// r_config_toggle (core->config, "scr.color");
|
||||
// refresh graph
|
||||
doPanelsRefresh (core);
|
||||
setRefreshAll (panels);
|
||||
break;
|
||||
case 'R':
|
||||
if (r_config_get_i (core->config, "scr.randpal")) {
|
||||
@ -1261,12 +1255,12 @@ repeat:
|
||||
replaceCmd (panels, PANEL_TITLE_DISASSEMBLY, PANEL_CMD_DISASSEMBLY);
|
||||
break;
|
||||
case 'J':
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (i = 0; i < PANEL_CONFIG_PAGE; i++) {
|
||||
handleDownKey (core);
|
||||
}
|
||||
break;
|
||||
case 'K':
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (i = 0; i < PANEL_CONFIG_PAGE; i++) {
|
||||
handleUpKey (core);
|
||||
}
|
||||
break;
|
||||
@ -1281,6 +1275,7 @@ repeat:
|
||||
break;
|
||||
case 'x':
|
||||
delCurPanel (panels);
|
||||
r_core_panels_layout (core->panels);
|
||||
setRefreshAll (panels);
|
||||
break;
|
||||
case 9: // TAB
|
||||
@ -1337,6 +1332,7 @@ repeat:
|
||||
if (panels->columnWidth + 4 < panels->can->w) {
|
||||
panels->columnWidth += 4;
|
||||
}
|
||||
r_core_panels_layout (panels);
|
||||
break;
|
||||
case 'L':
|
||||
r_cons_switchbuf (false);
|
||||
@ -1344,6 +1340,7 @@ repeat:
|
||||
if (panels->columnWidth - 4 > 0) {
|
||||
panels->columnWidth -= 4;
|
||||
}
|
||||
r_core_panels_layout (panels);
|
||||
break;
|
||||
case 'g':
|
||||
if (checkFunc (core)) {
|
||||
@ -1369,6 +1366,9 @@ repeat:
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
splitPanel (core);
|
||||
break;
|
||||
case ']':
|
||||
r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") + 1);
|
||||
break;
|
||||
@ -1380,6 +1380,7 @@ repeat:
|
||||
if (panels->layout >= layoutMaxCount) {
|
||||
panels->layout = 0;
|
||||
}
|
||||
r_core_panels_layout (panels);
|
||||
setRefreshAll (panels);
|
||||
break;
|
||||
case R_CONS_KEY_F1:
|
||||
|
Loading…
Reference in New Issue
Block a user