Some enhacements on the new colorized help

This commit is contained in:
pancake 2014-06-11 17:35:34 +02:00
parent 93f43d40fc
commit d7767b6de7
2 changed files with 49 additions and 41 deletions

View File

@ -2,25 +2,25 @@
static void show_help(RCore *core) {
const char * help_message[] = {
"Usage: t", "", "cparse types commands",
"t", "", "List all loaded types",
"t", " <type>", "Show type in 'pf' syntax",
"t*", "", "List types info in r2 commands",
"t-", " <name>", "Delete types by its name",
"t-*", "", "Remove all types",
"Usage: t", "", "# cparse types commands",
"t", "", "List all loaded types",
"t", " <type>", "Show type in 'pf' syntax",
"t*", "", "List types info in r2 commands",
"t-", " <name>", "Delete types by its name",
"t-*", "", "Remove all types",
//"t-!", "", "Use to open $EDITOR",
"td", " <string>", "Load types from string",
"td-", "<name>", "Undefine type by name",
"tf", " <addr>", "View linked type at given address",
"tl", "[?]", "Show/Link type to a address",
//"to", "", "List opened files",
"to", " -", "Open cfg.editor to load types",
"to", " <path>", "Load types from C header file",
"ts", " <key>=<value>... @ <link>.<addr>", "Set fields at given linked type", // old message on the next line, for clarity?
"td", " <string>","Load types from string",
"td-", "<name>", "Undefine type by name",
"tf", " <addr>", "View linked type at given address",
"tl", "[?]", "Show/Link type to a address",
//"to", "", "List opened files",
"to", " -", "Open cfg.editor to load types",
"to", " <path>", "Load types from C header file",
"ts", " <k>=<v>", "Set fields at curseek linked type",
//"| ts k=v k=v @ link.addr set fields at given linked type\n"
NULL
};
r_core_cmd_help(core, help_message);
r_core_cmd_help (core, help_message);
}
static int sdbforcb (void *p, const char *k, const char *v) {

View File

@ -8,36 +8,44 @@
* {"command", "args", "description",
* "command2", "args2", "description"}; */
R_API void r_core_cmd_help(RCore *core, const char * help[]) {
char padding[256];
int i, max_length, padding_length, use_colors;
char const * args_color_start;
char const * help_color_start;
char const * reset_colors;
RCons *cons;
char padding[256];
int i, max_length, padding_length, use_colors;
char const * args_color_start;
char const * help_color_start;
char const * reset_colors;
RCons *cons;
cons = r_cons_singleton();
cons = r_cons_singleton();
use_colors = core->print->flags & R_PRINT_FLAGS_COLOR;
use_colors = core->print->flags & R_PRINT_FLAGS_COLOR;
args_color_start = use_colors? cons->pal.prompt:"";
help_color_start = use_colors? cons->pal.comment: "";
reset_colors = use_colors? cons->pal.reset:"";
args_color_start = use_colors? cons->pal.pop: "";
help_color_start = use_colors? cons->pal.comment: "";
reset_colors = use_colors? cons->pal.reset: "";
max_length = 0;
for (i = 0; help[i]; i += 3) {
int len0 = strlen (help[i]);
int len1 = strlen (help[i+1]);
max_length = R_MAX (len0+len1, max_length);
}
max_length = 0;
for ( i = 0 ; help[i] != NULL ; i+=3 ) {
if( strlen(help[i]) + strlen(help[i+1]) > max_length ) {
max_length = strlen(help[i]) + strlen(help[i+1]);
}
}
for (i = 0; help[i]; i += 3) {
padding_length = max_length - \
(strlen(help[i]) + strlen(help[i+1]));
memset(padding, ' ', padding_length);
padding[padding_length] = '\0';
for ( i = 0 ; help[i] != NULL ; i+=3 ) {
padding_length = max_length - (strlen(help[i]) + strlen(help[i+1]));
memset(padding, ' ', padding_length);
padding[padding_length] = '\0';
r_cons_printf("| %s%s%s%s%s %s%s%s\n", help[i],
args_color_start, help[i+1], reset_colors, padding,
help_color_start, help[i+2], reset_colors);
}
if (i) {
r_cons_printf("|%s%s%s%s%s%s %s%s%s\n", i?" ":"",help[i],
args_color_start, help[i+1], reset_colors, padding,
help_color_start, help[i+2], reset_colors);
} else {
// no need to indent the first line
r_cons_printf ("|%s%s %s%s%s\n",
help_color_start,
help[i],help[i+1],help[i+2],
reset_colors);
}
}
}