diff --git a/libr/cons/canvas.c b/libr/cons/canvas.c index b5be8c67fd..15953ad84e 100644 --- a/libr/cons/canvas.c +++ b/libr/cons/canvas.c @@ -362,7 +362,6 @@ R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char c R_API void r_cons_canvas_line (RConsCanvas *c, int x, int y, int x2, int y2, int style) { if (c->linemode) { r_cons_canvas_line_square (c, x, y, x2, y2, style); - return; } else { r_cons_canvas_line_diagonal (c, x, y, x2, y2, style); } diff --git a/libr/cons/canvas_line.c b/libr/cons/canvas_line.c index 4d19d03312..35629776a6 100644 --- a/libr/cons/canvas_line.c +++ b/libr/cons/canvas_line.c @@ -12,23 +12,25 @@ enum { }; static void apply_line_style(RConsCanvas *c, int x, int y, int x2, int y2, int style){ + RCons *cons = r_cons_singleton (); switch (style) { case 0: // Unconditional jump - c->attr=Color_BLUE; + //c->attr=Color_BLUE; + c->attr = cons->pal.graph_trufae; //Color_GREEN; if (G (x, y)) W ("v"); if (G (x2, y2)) W ("V"); break; case 1: // Conditional jump, True branch - c->attr=Color_GREEN; + c->attr = cons->pal.graph_true; //Color_GREEN; if (G (x, y)) W ("t"); //\\"); if (G (x2, y2)) W ("\\"); break; case 2: // Conditional jump, False branch - c->attr=Color_RED; + c->attr = cons->pal.graph_false; //Color_RED; if (G (x, y)) W ("f"); if (G (x2, y2)) diff --git a/libr/cons/pal.c b/libr/cons/pal.c index a21b84f788..46c95aaeb9 100644 --- a/libr/cons/pal.c +++ b/libr/cons/pal.c @@ -62,6 +62,13 @@ R_API void r_cons_pal_init(const char *foo) { cons->pal.gui_background = Color_BLACK; cons->pal.gui_alt_background = Color_WHITE; cons->pal.gui_border = Color_BLACK; + + cons->pal.graph_box = Color_RESET; + cons->pal.graph_box2 = Color_BLUE; + cons->pal.graph_box3 = Color_MAGENTA; + cons->pal.graph_true = Color_GREEN; + cons->pal.graph_false = Color_RED; + cons->pal.graph_trufae = Color_BLUE; // single jump r_cons_pal_free (); cons->pal.list[0] = strdup (Color_RED); @@ -198,6 +205,13 @@ static struct { { "ai.seq", r_offsetof (RConsPalette, ai_seq) }, { "ai.ascii", r_offsetof (RConsPalette, ai_ascii) }, + { "graph.box", r_offsetof (RConsPalette, graph_box) }, + { "graph.box2", r_offsetof (RConsPalette, graph_box2) }, + { "graph.box3", r_offsetof (RConsPalette, graph_box3) }, + { "graph.true", r_offsetof (RConsPalette, graph_true) }, + { "graph.false", r_offsetof (RConsPalette, graph_false) }, + { "graph.trufae", r_offsetof (RConsPalette, graph_trufae) }, + { "gui.cflow", r_offsetof (RConsPalette, gui_cflow) }, { "gui.dataoffset", r_offsetof (RConsPalette, gui_dataoffset) }, { "gui.background", r_offsetof (RConsPalette, gui_background) }, diff --git a/libr/core/graph.c b/libr/core/graph.c index fe97d44a90..287e8545fa 100644 --- a/libr/core/graph.c +++ b/libr/core/graph.c @@ -66,9 +66,9 @@ struct agraph_refresh_data { #define G(x,y) r_cons_canvas_gotoxy (g->can, x, y) #define W(x) r_cons_canvas_write (g->can, x) -#define B(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h,NULL) -#define B1(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h,Color_BLUE) -#define B2(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h,Color_MAGENTA) +#define B(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h, g->color_box) +#define B1(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h, g->color_box2) +#define B2(x,y,w,h) r_cons_canvas_box(g->can, x,y,w,h, g->color_box3) #define L(x,y,x2,y2) r_cons_canvas_line(g->can, x,y,x2,y2,0) #define L1(x,y,x2,y2) r_cons_canvas_line(g->can, x,y,x2,y2,1) #define L2(x,y,x2,y2) r_cons_canvas_line(g->can, x,y,x2,y2,2) @@ -203,9 +203,9 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) { } static int **get_crossing_matrix (const RGraph *g, - const struct layer_t layers[], - int maxlayer, int i, int from_up, - int *n_rows) { + const struct layer_t layers[], + int maxlayer, int i, int from_up, + int *n_rows) { int len = layers[i].n_nodes; int **m; int j; @@ -690,12 +690,11 @@ static int cmp_dist (const size_t a, const size_t b) { static RGraphNode *get_sibling (const RAGraph *g, const RANode *n, int is_left, int is_adjust_class) { RGraphNode *res = NULL; - int pos; + int pos = n->pos_in_layer; if ((is_left && is_adjust_class) || (!is_left && !is_adjust_class)) - pos = n->pos_in_layer + 1; - else - pos = n->pos_in_layer - 1; + pos++; + else pos--; if (is_valid_pos (g, n->layer, pos)) res = g->layers[n->layer].nodes[pos]; @@ -760,18 +759,17 @@ static void adjust_class (const RAGraph *g, int is_left, } graph_foreach_anode (classes[c], it, gn, an) { - int old_val = hash_get_int (res, gn); - int new_val = is_left ? old_val + dist : old_val - dist; + const int old_val = hash_get_int (res, gn); + const int new_val = is_left ? old_val + dist : old_val - dist; hash_set (res, gn, new_val); } } static int place_nodes_val (const RAGraph *g, const RGraphNode *gn, - const RGraphNode *sibl, Sdb *res, int is_left) { + const RGraphNode *sibl, Sdb *res, int is_left) { if (is_left) return hash_get_int (res, sibl) + dist_nodes (g, sibl, gn); - else - return hash_get_int (res, sibl) - dist_nodes (g, gn, sibl); + return hash_get_int (res, sibl) - dist_nodes (g, gn, sibl); } static int place_nodes_sel_p (int newval, int oldval, int is_first, int is_left) { @@ -1930,6 +1928,9 @@ static void agraph_init(RAGraph *g) { g->is_small_nodes = R_FALSE; g->need_reload_nodes = R_TRUE; g->force_update_seek = R_TRUE; + g->color_box = Color_RESET; + g->color_box2 = Color_BLUE; // selected node + g->color_box3 = Color_MAGENTA; g->history = r_stack_new (INIT_HISTORY_CAPACITY); g->graph = r_graph_new (); g->nodes = sdb_new0 (); @@ -2161,6 +2162,13 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti r_cons_any_key (NULL); break; case 'R': + r_core_cmd0 (core, "ecr"); + g->color_box = core->cons->pal.graph_box; + g->color_box2 = core->cons->pal.graph_box2; + g->color_box3 = core->cons->pal.graph_box3; + g->color_true = core->cons->pal.graph_true; + g->color_false = core->cons->pal.graph_false; + break; case 'r': agraph_set_layout (g); break; @@ -2259,7 +2267,9 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti break; case -1: // EOF case 'q': - exit_graph = R_TRUE; + if (g->is_callgraph) { + agraph_toggle_callgraph(g); + } else exit_graph = R_TRUE; break; case 27: // ESC if (r_cons_readchar () == 91) { diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index ae845dc177..fc768c2ee1 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -103,6 +103,15 @@ typedef struct r_cons_palette_t { char *gui_background; char *gui_alt_background; char *gui_border; + + /* graph colors */ + char *graph_box; + char *graph_box2; + char *graph_box3; + char *graph_true; + char *graph_false; + char *graph_trufae; + #define R_CONS_PALETTE_LIST_SIZE 8 char *list[R_CONS_PALETTE_LIST_SIZE]; } RConsPalette; @@ -543,6 +552,11 @@ typedef struct r_ascii_graph_t { struct layer_t *layers; int n_layers; RList *dists; /* RList */ + const char *color_box; + const char *color_box2; + const char *color_box3; + const char *color_true; + const char *color_false; } RAGraph; #ifdef R_API