From 5be9cdd59c9d622da292f12970d0c4ee756a1acc Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 4 Aug 2024 12:57:37 +0200 Subject: [PATCH] Fix bug in V;! not bringing back the mouse ##visual --- libr/cons/cons.c | 39 +++++++++++++++------------------------ libr/core/visual.c | 7 ++++--- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/libr/cons/cons.c b/libr/cons/cons.c index b609264f19..df2a0ec509 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -642,43 +642,34 @@ R_API void r_cons_enable_highlight(const bool enable) { } R_API bool r_cons_enable_mouse(const bool enable) { - if ((I->mouse && enable) || (!I->mouse && !enable)) { - return I->mouse; - } + bool enabled = I->mouse; #if R2__WINDOWS__ + HANDLE h = GetStdHandle (STD_INPUT_HANDLE); + GetConsoleMode (h, &mode); + DWORD mode |= ENABLE_EXTENDED_FLAGS; + mode |= enable + ? (mode | ENABLE_MOUSE_INPUT) & ~ENABLE_QUICK_EDIT_MODE + : (mode & ~ENABLE_MOUSE_INPUT) | ENABLE_QUICK_EDIT_MODE; + if (SetConsoleMode (h, mode)) { + I->mouse = enable; + } +#else if (I->vtmode == 2) { -#endif const char *click = enable ? "\x1b[?1000;1006;1015h" : "\x1b[?1000;1006;1015l"; // : "\x1b[?1001r\x1b[?1000l"; // : "\x1b[?1000;1006;1015l"; // const char *old = enable ? "\x1b[?1001s" "\x1b[?1000h" : "\x1b[?1001r" "\x1b[?1000l"; - bool enabled = I->mouse; const size_t click_len = strlen (click); if (write (2, click, click_len) != click_len) { - return false; + enabled = false; + } else { + I->mouse = enable; } - I->mouse = enable; - return enabled; -#if R2__WINDOWS__ } - DWORD mode; - HANDLE h; - bool enabled = I->mouse; - h = GetStdHandle (STD_INPUT_HANDLE); - GetConsoleMode (h, &mode); - mode |= ENABLE_EXTENDED_FLAGS; - mode = enable - ? (mode | ENABLE_MOUSE_INPUT) & ~ENABLE_QUICK_EDIT_MODE - : (mode & ~ENABLE_MOUSE_INPUT) | ENABLE_QUICK_EDIT_MODE; - if (SetConsoleMode (h, mode)) { - I->mouse = enable; - } - return enabled; -#else - return false; #endif + return enabled; } R_API RCons *r_cons_new(void) { diff --git a/libr/core/visual.c b/libr/core/visual.c index abb9e74f99..5bbba2e08a 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -1351,19 +1351,20 @@ R_API int r_core_visual_prevopsz(RCore *core, ut64 addr) { } static void addComment(RCore *core, ut64 addr) { - char buf[1024]; r_cons_printf ("Enter comment for reference:\n"); r_core_visual_showcursor (core, true); r_cons_flush (); r_cons_set_raw (false); r_line_set_prompt (PROMPTSTR); r_cons_enable_mouse (false); + char buf[1024]; if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { buf[0] = '\0'; } - r_core_cmdf (core, "\"\"@0x%08"PFMT64x"\"\"CC %s", addr, buf); - r_core_visual_showcursor (core, false); + r_core_cmdf (core, "'@0x%08"PFMT64x"'CC %s", addr, buf); r_cons_set_raw (true); + r_cons_enable_mouse (r_config_get_b (core->config, "scr.wheel")); + r_core_visual_showcursor (core, false); } static void add_ref(RCore *core) {