mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
Enable click mouse input on Windows ##cons
This commit is contained in:
parent
564f6dc07c
commit
1d3a2deb96
@ -636,7 +636,11 @@ R_API int r_cons_eof() {
|
||||
}
|
||||
|
||||
R_API void r_cons_gotoxy(int x, int y) {
|
||||
#if __WINDOWS__
|
||||
r_cons_w32_gotoxy (1, x, y);
|
||||
#else
|
||||
r_cons_printf ("\x1b[%d;%dH", y, x);
|
||||
#endif
|
||||
}
|
||||
|
||||
R_API void r_cons_print_clear() {
|
||||
@ -693,8 +697,12 @@ R_API void r_cons_reset_colors() {
|
||||
}
|
||||
|
||||
R_API void r_cons_clear() {
|
||||
r_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN);
|
||||
I.lines = 0;
|
||||
#if __WINDOWS__
|
||||
r_cons_w32_clear ();
|
||||
#else
|
||||
r_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cons_grep_reset(RConsGrep *grep) {
|
||||
@ -1277,8 +1285,8 @@ R_API int r_cons_get_size(int *rows) {
|
||||
#if __WINDOWS__
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
bool ret = GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
|
||||
I.columns = (csbi.srWindow.Right - csbi.srWindow.Left) - 1;
|
||||
I.rows = csbi.srWindow.Bottom - csbi.srWindow.Top; // last row empty
|
||||
I.columns = (csbi.srWindow.Right - csbi.srWindow.Left) + 1;
|
||||
I.rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||
if (!ret || I.columns == -1 && I.rows == 0) {
|
||||
// Stdout is probably redirected so we set default values
|
||||
I.columns = 80;
|
||||
|
@ -93,7 +93,7 @@ static int __parseMouseEvent() {
|
||||
|
||||
R_API int r_cons_arrow_to_hjkl(int ch) {
|
||||
#if __WINDOWS__
|
||||
return ch;
|
||||
return ch < 2 ? 0 : ch;
|
||||
#endif
|
||||
I->mouse_event = 0;
|
||||
/* emacs */
|
||||
@ -369,47 +369,54 @@ static int __cons_readchar_w32 (ut32 usec) {
|
||||
BOOL bCtrl = FALSE;
|
||||
DWORD mode, out;
|
||||
HANDLE h;
|
||||
INPUT_RECORD irInBuf[128];
|
||||
INPUT_RECORD irInBuf;
|
||||
int i, o;
|
||||
bool resize = false;
|
||||
void *bed;
|
||||
h = GetStdHandle (STD_INPUT_HANDLE);
|
||||
GetConsoleMode (h, &mode);
|
||||
SetConsoleMode (h, ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS);
|
||||
do_it_again:
|
||||
bed = r_cons_sleep_begin ();
|
||||
if (usec) {
|
||||
if (WaitForSingleObject (h, usec) == WAIT_TIMEOUT) {
|
||||
r_cons_sleep_end (bed);
|
||||
return -1;
|
||||
do {
|
||||
bed = r_cons_sleep_begin ();
|
||||
if (usec) {
|
||||
if (WaitForSingleObject (h, usec) == WAIT_TIMEOUT) {
|
||||
r_cons_sleep_end (bed);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = ReadConsoleInput (h, irInBuf, 128, &out);
|
||||
r_cons_enable_mouse (true);
|
||||
r_cons_sleep_end (bed);
|
||||
if (ret) {
|
||||
for (i = 0; i < out; i++) {
|
||||
if (irInBuf[i].EventType == MOUSE_EVENT) {
|
||||
if (irInBuf[i].Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) {
|
||||
if (irInBuf[i].Event.MouseEvent.dwButtonState & 0xFF000000) {
|
||||
ret = ReadConsoleInput (h, &irInBuf, 1, &out);
|
||||
r_cons_enable_mouse (true);
|
||||
r_cons_sleep_end (bed);
|
||||
if (ret) {
|
||||
if (irInBuf.EventType == MOUSE_EVENT) {
|
||||
if (irInBuf.Event.MouseEvent.dwEventFlags == MOUSE_MOVED) {
|
||||
continue;
|
||||
}
|
||||
if (irInBuf.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) {
|
||||
if (irInBuf.Event.MouseEvent.dwButtonState & 0xFF000000) {
|
||||
ch = bCtrl ? 'J' : 'j';
|
||||
} else {
|
||||
ch = bCtrl ? 'K' : 'k';
|
||||
}
|
||||
break;
|
||||
I->mouse_event = 1;
|
||||
}
|
||||
switch (irInBuf[i].Event.MouseEvent.dwButtonState) {
|
||||
switch (irInBuf.Event.MouseEvent.dwButtonState) {
|
||||
case FROM_LEFT_1ST_BUTTON_PRESSED:
|
||||
r_cons_set_click (irInBuf.Event.MouseEvent.dwMousePosition.X + 1, irInBuf.Event.MouseEvent.dwMousePosition.Y + 1);
|
||||
ch = 1;
|
||||
break;
|
||||
case RIGHTMOST_BUTTON_PRESSED:
|
||||
r_cons_enable_mouse (false);
|
||||
break;
|
||||
} // TODO: Handle more buttons?
|
||||
}
|
||||
if (irInBuf[i].EventType == KEY_EVENT) {
|
||||
if (irInBuf[i].Event.KeyEvent.bKeyDown) {
|
||||
ch = irInBuf[i].Event.KeyEvent.uChar.AsciiChar;
|
||||
bCtrl=irInBuf[i].Event.KeyEvent.dwControlKeyState & 8;
|
||||
if (irInBuf[i].Event.KeyEvent.uChar.AsciiChar == 0) {
|
||||
if (irInBuf.EventType == KEY_EVENT) {
|
||||
if (irInBuf.Event.KeyEvent.bKeyDown) {
|
||||
ch = irInBuf.Event.KeyEvent.uChar.AsciiChar;
|
||||
bCtrl = irInBuf.Event.KeyEvent.dwControlKeyState & 8;
|
||||
if (irInBuf.Event.KeyEvent.uChar.AsciiChar == 0) {
|
||||
ch = 0;
|
||||
switch (irInBuf[i].Event.KeyEvent.wVirtualKeyCode) {
|
||||
switch (irInBuf.Event.KeyEvent.wVirtualKeyCode) {
|
||||
case VK_DOWN: // key down
|
||||
ch = bCtrl ? 'J' : 'j';
|
||||
break;
|
||||
@ -471,27 +478,18 @@ do_it_again:
|
||||
}
|
||||
}
|
||||
}
|
||||
if (irInBuf[i].EventType == WINDOW_BUFFER_SIZE_EVENT) {
|
||||
if (irInBuf.EventType == WINDOW_BUFFER_SIZE_EVENT) {
|
||||
resize = true;
|
||||
}
|
||||
if (resize) {
|
||||
resizeWin ();
|
||||
resize = false;
|
||||
}
|
||||
}
|
||||
if (resize) {
|
||||
resizeWin ();
|
||||
resize = false;
|
||||
}
|
||||
}
|
||||
FlushConsoleInputBuffer (h);
|
||||
if (ch == 0) {
|
||||
goto do_it_again;
|
||||
}
|
||||
FlushConsoleInputBuffer (h);
|
||||
} while (ch == 0);
|
||||
SetConsoleMode (h, mode);
|
||||
/*r_cons_gotoxy (1, 2);
|
||||
r_cons_printf ("\n");
|
||||
r_cons_printf ("| buf = %x |\n", ch);
|
||||
r_cons_printf ("\n");
|
||||
r_cons_flush ();
|
||||
r_sys_sleep (1);*/
|
||||
return ch;
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -19,7 +19,7 @@ static void __fill_tail(int cols, int lines) {
|
||||
}
|
||||
}
|
||||
|
||||
static void __clear_w32() {
|
||||
R_API void r_cons_w32_clear(void) {
|
||||
static HANDLE hStdout = NULL;
|
||||
static CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
const COORD startCoords = { 0, 0 };
|
||||
@ -251,7 +251,7 @@ static int r_cons_w32_hprint(DWORD hdl, const ut8 *ptr, int len, bool vmode) {
|
||||
str = ptr + 1;
|
||||
continue;
|
||||
} else if (ptr[0]=='2'&&ptr[1]=='J') {
|
||||
__clear_w32 ();
|
||||
r_cons_w32_clear ();
|
||||
esc = 0;
|
||||
ptr = ptr + 1;
|
||||
str = ptr + 1;
|
||||
|
@ -5533,8 +5533,8 @@ repeat:
|
||||
panels->curnode = i;
|
||||
__set_curnode(core, i);
|
||||
__setRefreshAll (core, true, true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
goto repeat;
|
||||
|
@ -790,6 +790,7 @@ R_API void r_cons_pipe_close(int fd);
|
||||
|
||||
#if __WINDOWS__
|
||||
R_API bool r_cons_is_ansicon(void);
|
||||
R_API void r_cons_w32_clear(void);
|
||||
R_API void r_cons_w32_gotoxy(int fd, int x, int y);
|
||||
R_API int r_cons_w32_print(const ut8 *ptr, int len, bool vmode);
|
||||
R_API int r_cons_win_printf(bool vmode, const char *fmt, ...);
|
||||
|
@ -1772,7 +1772,7 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) {
|
||||
const char *s, *s_start;
|
||||
size_t r_len, str_len = 0, nr_of_lines = 0;
|
||||
ut32 ch = 0, cw = 0;
|
||||
if ((x2 - x) < 1 || (y2 - y) < 1 || !str) {
|
||||
if (x2 <= x || y2 <= y || !str) {
|
||||
return strdup ("");
|
||||
}
|
||||
s = s_start = str;
|
||||
|
Loading…
Reference in New Issue
Block a user