diff options
-rw-r--r-- | cd-tool.cpp | 115 |
1 files changed, 113 insertions, 2 deletions
diff --git a/cd-tool.cpp b/cd-tool.cpp index 66ad69e..5ec9385 100644 --- a/cd-tool.cpp +++ b/cd-tool.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cd-tool.cpp,v 1.31 2004-07-30 00:47:58 pixel Exp $ */ +/* $Id: cd-tool.cpp,v 1.32 2004-07-30 10:01:34 pixel Exp $ */ #define WIP @@ -41,6 +41,115 @@ #include "cd-tool-hc.h" +#ifdef _WIN32 + +#include <readline/rldefs.h> + +#include <windows.h> +#include <ctype.h> +#include <conio.h> + +#define EXT_PREFIX 0x1f8 + +#define KEV irec.Event.KeyEvent /* to make life easier */ +#define KST irec.Event.KeyEvent.dwControlKeyState + + +static int pending_key = 0; +static int pending_count = 0; +static int pending_prefix = 0; + +extern int _rl_last_c_pos; /* imported from display.c */ +extern int _rl_last_v_pos; +extern int rl_dispatching; /* imported from readline.c */ +extern int rl_point; +extern int rl_done; +extern int rl_visible_prompt_length; + +extern "C" { +extern int haveConsole; /* imported from rltty.c */ +extern HANDLE hStdout, hStdin; +} + +int my_getc (FILE * stream) +{ + int key; + + if ( pending_count ) + { + --pending_count; + if ( pending_prefix && (pending_count & 1) ) + return pending_prefix; + else + return pending_key; + } + + while ( 1 ) + { + DWORD dummy; + + if (WaitForSingleObject(hStdin, WAIT_FOR_INPUT) != WAIT_OBJECT_0) + { + if ( rl_done ) + return( 0 ); + else + continue; + } + if ( haveConsole & FOR_INPUT ) + { + INPUT_RECORD irec; + ReadConsoleInput(hStdin, &irec, 1, &dummy); + switch(irec.EventType) + { + case KEY_EVENT: + if ( KEV.bKeyDown + && ((KEV.wVirtualKeyCode < VK_SHIFT) || (KEV.wVirtualKeyCode > VK_MENU)) ) + { + int mask = 0; + + key = KEV.uChar.AsciiChar & 0xff; +// if ( KST & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) ) +// mask=0x100; + if ( key ) + { + /* Ascii direct */ + pending_count = KEV.wRepeatCount - 1; + pending_key = key; + pending_prefix = 0; + if ( mask ) + key = tolower(key) | mask; + } + else + /* Others prefixed */ + { + key = EXT_PREFIX; + if ( mask ) + key |= 4; + if (KST & SHIFT_PRESSED) + key |= 1; + if (KST & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + key |= 2; + mask |= EXT_PREFIX; + pending_count = (KEV.wRepeatCount << 1) - 1; + pending_key = KEV.wVirtualKeyCode; + pending_prefix = key; + } + return key; + } + break; + default: + break; + } + } + else + { + ReadFile(hStdin, &key, 1, &dummy, NULL); + return key; + } + } +} +#endif + bool interactive = false; cdutils * cdutil = 0; isobuilder * build = 0; @@ -494,8 +603,10 @@ virtual int startup() throw (GeneralException) { /* Interactive mode loop */ strcpy(prompt, "> "); +#ifdef _WIN32 + rl_getc_function = my_getc; +#endif rl_bind_key('\t', rl_insert); - rl_getc_function = getc; while (interactive) { /* Basic usage of readline */ if (line_read) |