Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortcuts in mini graph + colorize shortcuts #10675

Merged
merged 2 commits into from Jul 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions libr/core/graph.c
Expand Up @@ -32,7 +32,7 @@ static const char *mousemodes[] = {
#define PAGEKEY_SPEED (h / 2)
/* 15 */
#define MINIGRAPH_NODE_TEXT_CUR "<@@@@@@>"
#define MINIGRAPH_NODE_MIN_WIDTH 8
#define MINIGRAPH_NODE_MIN_WIDTH 12
#define MINIGRAPH_NODE_TITLE_LEN 4
#define MINIGRAPH_NODE_CENTER_X 3
#define MININODE_MIN_WIDTH 16
Expand Down Expand Up @@ -231,6 +231,18 @@ static void update_node_dimension(const RGraph *g, int is_mini, int zoom, int ed
}
}

static void append_shortcut (const RAGraph *g, char *title, char *nodetitle, int left) {
char *shortcut = sdb_get (g->db, sdb_fmt ("agraph.nodes.%s.shortcut", nodetitle), 0);
if (shortcut) {
if (g->can->color) {
strncat (title, sdb_fmt ("\x1b[33m[g%s]", shortcut), left);
} else {
strncat (title, sdb_fmt ("[g%s]", shortcut), left);
}
free (shortcut);
}
}

static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool details) {
char title[TITLE_LEN];
int x, delta_x = 0;
Expand Down Expand Up @@ -273,8 +285,13 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool d
str += l - MINIGRAPH_NODE_TITLE_LEN;
}
}
snprintf (title, sizeof (title) - 1, "__%s__", str);
W (title + delta_x);
if (g->can->color) {
snprintf (title, sizeof (title) - 1, "%s__%s__", Color_RESET, str);
} else {
snprintf (title, sizeof (title) - 1, "__%s__", str);
}
append_shortcut (g, title, n->title, sizeof (title) - strlen (title) - 1);
W (r_str_ansi_crop (title, delta_x, 0, 20, 1));
}
} else {
snprintf (title, sizeof (title) - 1,
Expand All @@ -300,7 +317,6 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) {
char title[TITLE_LEN];
char *body;
int x, y;
char *shortcut;

x = n->x + g->can->sx;
y = n->y + g->can->sy;
Expand All @@ -313,19 +329,16 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) {
if (y < -1) {
delta_y = R_MIN (n->h - BORDER_HEIGHT - 1, -y - MARGIN_TEXT_Y);
}
shortcut = sdb_get (g->db, sdb_fmt ("agraph.nodes.%s.shortcut", n->title), 0);
/* print the title */
if (cur) {
snprintf (title, sizeof (title) - 1, "[%s]", n->title);
} else {
snprintf (title, sizeof (title) - 1, " %s", n->title);
}
if (shortcut) {
strncat (title, sdb_fmt (" ;[g%s]", shortcut), sizeof (title) - strlen (title) - 1);
free (shortcut);
char *color = g->can->color ? Color_RESET : "";
snprintf (title, sizeof (title) - 1, " %s%s ", color, n->title);
append_shortcut (g, title, n->title, sizeof (title) - strlen (title) - 1);
}
if ((delta_x < strlen (title)) && G (n->x + MARGIN_TEXT_X + delta_x, n->y + 1)) {
W (title + delta_x);
W (r_str_ansi_crop (title, delta_x, 0, n->w - BORDER_WIDTH, 1));
}

/* print the body */
Expand Down