Visual color theme editor available from panels ##visual

* Fix visual glitches in VE[hl]
* Handle empty 'VEc' properly
* Handle ':' command prompt in the visual theme editor
This commit is contained in:
pancake 2022-04-09 12:10:32 +02:00
parent 8eceab96d4
commit f089f6f985
3 changed files with 32 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2009-2021 - pancake */
/* radare2 - LGPL - Copyright 2009-2022 - pancake */
#include <stddef.h>
#include <stdbool.h>
@ -233,10 +233,12 @@ static void nextpal(RCore *core, int mode) {
r_list_free (files);
return;
}
#if 0
eprintf ("%s %s %s\n",
r_str_get (nfn),
r_str_get (core->theme),
r_str_get (fn));
#endif
if (nfn && !strcmp (nfn, core->theme)) {
r_list_free (files);
files = NULL;
@ -275,10 +277,12 @@ static void nextpal(RCore *core, int mode) {
r_list_free (files);
return;
}
#if 0
eprintf ("%s %s %s\n",
r_str_get (nfn),
r_str_get (core->theme),
r_str_get (fn));
#endif
if (nfn && !strcmp (nfn, core->theme)) {
free (core->theme);
core->theme = strdup (fn);
@ -304,7 +308,7 @@ done:
if (mode == 'l' && !core->theme && !r_list_empty (files)) {
//nextpal (core, mode);
} else if (mode == 'n' || mode == 'p') {
if (core->theme) {
if (R_STR_ISNOTEMPTY (core->theme)) {
r_core_cmdf (core, "eco %s", core->theme);
}
}
@ -318,7 +322,7 @@ done:
}
R_API void r_core_echo(RCore *core, const char *input) {
if (!strncmp (input, "64 ", 3)) {
if (r_str_startswith (input, "64 ")) {
char *buf = strdup (input);
r_base64_decode ((ut8*)buf, input + 3, -1);
if (*buf) {

View File

@ -4056,6 +4056,9 @@ static void __create_modal(RCore *core, RPanel *panel, Sdb *menu_db) {
}
}
switch (key) {
case 'E':
r_core_visual_colors (core);
break;
case 'e':
{
__free_modal (&modal);
@ -4065,7 +4068,7 @@ static void __create_modal(RCore *core, RPanel *panel, Sdb *menu_db) {
}
free (cmd);
}
break;
break;
case 'j':
modal->idx++;
__update_modal (core, menu_db, modal);
@ -6869,6 +6872,9 @@ virtualmouse:
case 'M':
__handle_visual_mark (core);
break;
case 'E':
r_core_visual_colors (core);
break;
case 'e':
{
char *cmd = __show_status_input (core, "New command: ");

View File

@ -501,14 +501,14 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
case 'H':
{
int y = R_MAX (x - 8, 0);
x = y - y%8;
x = y - y % 8;
}
break;
case 'L':
case 9:
{
int y = R_MIN (x + 8, nbits - 8);
x = y - y%8;
x = y - y % 8;
}
break;
case 'j':
@ -532,7 +532,7 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
buf[x/8] = rotate_nibble (buf [(x / 8)], -1);
break;
case '<':
buf[x/8] = rotate_nibble (buf [(x / 8)], 1);
buf[x / 8] = rotate_nibble (buf [(x / 8)], 1);
break;
case 'i':
{
@ -540,7 +540,7 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
const char *line = r_line_readline ();
ut64 num = r_num_math (core->num, line);
if (num || (!num && *line == '0')) {
buf[x/8] = num;
buf[x / 8] = num;
}
}
break;
@ -686,12 +686,9 @@ static bool sdbforcb(void *p, const char *k, const char *v) {
}
if (use_color && *pre == '>') {
r_cons_printf ("%s %s %s\n"Color_RESET, color_sel,
(vt->t_idx == vt->t_ctr)?
">":" ", k);
(vt->t_idx == vt->t_ctr)? ">": " ", k);
} else {
r_cons_printf (" %s %s\n",
(vt->t_idx == vt->t_ctr)?
">":" ", k);
r_cons_printf (" %s %s\n", (vt->t_idx == vt->t_ctr)? ">": " ", k);
}
}
vt->t_ctr ++;
@ -4404,8 +4401,8 @@ R_API void r_core_visual_colors(RCore *core) {
"' to change foreground/background color\n");
r_cons_printf ("# Export colorscheme with command 'ec* > filename'\n");
r_cons_printf ("# Preview command: '%s' - Press 'c' to change it\n", preview_cmd);
r_cons_printf ("# Selected colorscheme : %s - Use 'hl' or left/right arrow keys to change colorscheme\n", r_str_get_fail (curtheme, "default"));
r_cons_printf ("# Selected element: %s - Use 'jk' or up/down arrow keys to change element\n", k);
r_cons_printf ("# Theme (eco): %s - Use 'hl' or left/right arrow keys to change colorscheme\n", r_str_get_fail (curtheme, "default"));
r_cons_printf ("# Item (%s) - Use 'jk' or up/down arrow keys to change element\n", k);
r_cons_printf ("# ec %s %s # %d (\\x1b%.*s)",
k, color, atoi (cstr+7), esc ? (int)(esc - cstr - 1) : (int)strlen (cstr + 1), cstr+1);
if (esc) {
@ -4459,6 +4456,9 @@ R_API void r_core_visual_colors(RCore *core) {
opt = r_cons_pal_len () - 1;
break;
case ':':
r_core_visual_prompt_input (core);
break;
case ',':
r_cons_pal_random ();
break;
case '.':
@ -4469,7 +4469,13 @@ R_API void r_core_visual_colors(RCore *core) {
case 'c':
r_line_set_prompt ("Preview command> ");
r_cons_show_cursor (true);
r_cons_fgets (preview_cmd, sizeof (preview_cmd), 0, NULL);
{
char newcmd[128] = {0};
r_cons_fgets (newcmd, sizeof (newcmd), 0, NULL);
if (*newcmd) {
r_str_ncpy (preview_cmd, newcmd, sizeof (preview_cmd) - 1);
}
}
r_cons_show_cursor (false);
}
if (opt != oopt) {