Handle arrow and page up/down keys on W32

This commit is contained in:
skuater 2015-01-14 23:31:29 +01:00 committed by pancake
parent ed00174649
commit 9b4044046e
4 changed files with 55 additions and 7 deletions

View File

@ -164,6 +164,7 @@ R_API RCons *r_cons_new () {
I.line = r_line_new ();
I.highlight = NULL;
I.event_interrupt = NULL;
I.is_wine = -1;
I.fps = 0;
I.blankline = R_TRUE;
I.teefile = NULL;

View File

@ -2,6 +2,11 @@
#include <r_cons.h>
#include <string.h>
#if __WINDOWS__
#include <conio.h>
#endif
#define I r_cons_singleton()
#if 0
//__UNIX__
@ -208,6 +213,31 @@ R_API void r_cons_any_key() {
//r_cons_strcat ("\x1b[2J\x1b[0;0H"); // wtf?
}
#if __WINDOWS__
static char getwinkey() {
char i=0;
int res=0;
for(i=8; i <= 255; i++) {
res = GetAsyncKeyState (i);
if (res & 0x7FFF) {
switch (i) {
case 33: return 'K';
case 34: return 'J';
case 37: return 'h';
case 38: return 'k';
case 39: return 'l';
case 40: return 'j';
default:
if (i>=0x30 && i<=0x5a)
return '1';
else return '2';
}
}
}
return '2';
}
#endif
R_API int r_cons_readchar() {
char buf[2];
buf[0] = -1;
@ -215,10 +245,26 @@ R_API int r_cons_readchar() {
BOOL ret;
DWORD out;
DWORD mode;
char b;
HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
GetConsoleMode (h, &mode);
SetConsoleMode (h, 0); // RAW
ret = ReadConsole (h, buf, 1, &out, NULL);
ignore:
if (!I->is_wine) {
while (!_kbhit ());
b = getwinkey ();
if (b=='2')
goto ignore;
else if (b=='1')
ret = ReadConsole (h, buf, 1, &out, NULL);
else {
buf[0]=b;
ret=1;
}
} else {
ret = ReadConsole (h, buf, 1, &out, NULL);
}
FlushConsoleInputBuffer(h);
if (!ret)
return -1;
SetConsoleMode (h, mode);

View File

@ -1,9 +1,9 @@
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <r_cons.h>
#define I r_cons_singleton()
#if __WINDOWS__
static int is_wine = -1;
static void fill_tail (int cols, int lines) {
/* fill the rest of screen */
lines++; // hack
@ -25,7 +25,7 @@ static void w32_clear() {
const COORD startCoords = { 0, 0 };
DWORD dummy;
if (is_wine) {
if (I->is_wine==1) {
write (1, "\x1b[0;0H", 6);
write (1, "\x1b[0m", 4);
write (1, "\x1b[2J", 4);
@ -44,7 +44,7 @@ void w32_gotoxy(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
if (is_wine) {
if (I->is_wine==1) {
write (1, "\x1b[0;0H", 6);
}
if (!hStdout)
@ -73,8 +73,8 @@ R_API int r_cons_w32_print(const ut8 *ptr, int len, int vmode) {
int inv = 0;
int linelen = 0;
int lines, cols = r_cons_get_size (&lines);
if (is_wine==-1) {
is_wine = r_file_is_directory ("/proc")? 1: 0;
if (I->is_wine==-1) {
I->is_wine = r_file_is_directory ("/proc")? 1: 0;
}
if (len<0)

View File

@ -167,6 +167,7 @@ typedef struct r_cons_t {
char *highlight;
int null; // if set, does not show anything
int mouse;
int is_wine;
RConsPalette pal;
struct r_line_t *line;
const char **vline;