diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index fa7dc3e448..d9caf843b6 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -37,7 +37,7 @@ static inline bool is_word_break_char(char ch, bool mode) { int len = sizeof (word_break_characters) / sizeof (word_break_characters[0]); - for (i = 0; i < len; ++i) { + for (i = 0; i < len; i++) { if (ch == word_break_characters[i]) { return true; } @@ -1703,7 +1703,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { break; } r_cons_readchar (); - ch = r_cons_readchar (); + int fkey = ch - '0'; #endif switch (ch) { case 0x41: @@ -1738,6 +1738,17 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { I.buffer.index = I.buffer.length; } break; + default: +#if __WINDOWS__ + // ... +#else + { + if (I.cb_fkey) { + I.cb_fkey (I.user, fkey); + } + } +#endif + break; } r_cons_set_raw (1); break; diff --git a/libr/cons/line.c b/libr/cons/line.c index 533bbd23e2..f9653eb228 100644 --- a/libr/cons/line.c +++ b/libr/cons/line.c @@ -46,6 +46,8 @@ R_API void r_line_clipboard_push (const char *str) { R_API void r_line_set_prompt(const char *prompt) { free (I.prompt); I.prompt = strdup (prompt); + RCons *cons = r_cons_singleton (); + I.cb_fkey = cons->cb_fkey; } // handle const or dynamic prompts? diff --git a/libr/core/core.c b/libr/core/core.c index 9754f660e5..8dab62d70e 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2009-2019 - pancake */ +/* radare2 - LGPL - Copyright 2009-2020 - pancake */ #include #include @@ -2646,6 +2646,7 @@ R_API bool r_core_init(RCore *core) { core->cons->line->user = core; core->cons->line->cb_editor = \ (RLineEditorCb)&r_core_editor; + core->cons->line->cb_fkey = core->cons->cb_fkey; } #if __EMSCRIPTEN__ core->cons->user_fgets = NULL; @@ -2787,8 +2788,20 @@ R_API bool r_core_init(RCore *core) { return 0; } +R_API void __cons_cb_fkey(RCore *core, int fkey) { + char buf[32]; + snprintf (buf, sizeof (buf), "key.f%d", fkey); + const char *v = r_config_get (core->config, buf); + if (v && *v) { + r_cons_printf ("%s\n", v); + r_core_cmd0 (core, v); + r_cons_flush (); + } +} + R_API void r_core_bind_cons(RCore *core) { core->cons->num = core->num; + core->cons->cb_fkey = (RConsFunctionKey)__cons_cb_fkey; core->cons->cb_editor = (RConsEditorCallback)r_core_editor; core->cons->cb_break = (RConsBreakCallback)r_core_break; core->cons->cb_sleep_begin = (RConsSleepBeginCallback)r_core_sleep_begin; diff --git a/libr/include/r_cons.h b/libr/include/r_cons.h index d086d9ecd8..298cf254a0 100644 --- a/libr/include/r_cons.h +++ b/libr/include/r_cons.h @@ -424,6 +424,7 @@ typedef void (*RConsBreakCallback)(void *core); typedef void *(*RConsSleepBeginCallback)(void *core); typedef void (*RConsSleepEndCallback)(void *core, void *user); typedef void (*RConsQueueTaskOneshot)(void *core, void *task, void *user); +typedef void (*RConsFunctionKey)(void *core, int fkey); typedef enum { COLOR_MODE_DISABLED = 0, COLOR_MODE_16, COLOR_MODE_256, COLOR_MODE_16M } RConsColorMode; @@ -487,6 +488,7 @@ typedef struct r_cons_t { RConsSleepEndCallback cb_sleep_end; RConsClickCallback cb_click; RConsQueueTaskOneshot cb_task_oneshot; + RConsFunctionKey cb_fkey; void *user; // Used by #if __UNIX__ @@ -1045,6 +1047,8 @@ struct r_line_t { RLineHistoryUpCb cb_history_up; RLineHistoryDownCb cb_history_down; RLineEditorCb cb_editor; + // RLineFunctionKeyCb cb_fkey; + RConsFunctionKey cb_fkey; /* state , TODO: use more bool */ int echo; int has_echo;