Create  Edit  Diff  FrontPage  Index  Search  Changes  Login

The Backyard - readline for win32 Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

static int readline_getc(FILE *);
static int
readline_getc(FILE *input)
{
     rb_io_t *ifp = 0;
     VALUE c;
     if (!readline_instream) return rl_getc(input);
     GetOpenFile(readline_instream, ifp);
     if (rl_instream != ifp->stdio_file) return rl_getc(input);
#if !defined(_WIN32)
     c = rb_funcall(readline_instream, id_getbyte, 0, 0);
     if (NIL_P(c)) return EOF;
     return NUM2CHR(c);
#else
     {
         INPUT_RECORD ir;
         int n;
         static int prior_key = '0';
         for (;;) {
             if (prior_key > 0xff) {
                 prior_key = rl_getc(ifp->stdio_file);
                 return prior_key;
            }
            if
(PeekConsoleInput((HANDLE)_get_osfhandle(ifp->fd), &ir, 1, &n)
                 && n == 1) {
                 if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) {
                     return prior_key = rl_getc(ifp->stdio_file);
                     return prior_key;

                 } else {
                     ReadConsoleInput((HANDLE)_get_osfhandle(ifp->fd), &ir, 1, &n);
                 }
             } else {
                 HANDLE h = (HANDLE)_get_osfhandle(ifp->fd);
                 rb_w32_wait_events(&h, 1, 10);
             }
         }
     }
#endif
}

これはダメ。readline.dll内でペンディングしているやつがあっても待ち状態になってしまう。