mirror of
https://github.com/radareorg/radare2.git
synced 2025-03-04 12:27:40 +00:00
Fix #15359 - Enable key.f# keys to be used in the shell ##cons
This commit is contained in:
parent
b714b5fe72
commit
2b74ff5cda
@ -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;
|
||||
|
@ -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?
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2009-2019 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2009-2020 - pancake */
|
||||
|
||||
#include <r_core.h>
|
||||
#include <r_socket.h>
|
||||
@ -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;
|
||||
|
@ -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 <RCore*>
|
||||
#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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user