summaryrefslogtreecommitdiff
path: root/ext/readline
diff options
context:
space:
mode:
authorkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-21 04:30:14 +0000
committerkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-21 04:30:14 +0000
commite49f890906507b49ac81328e1e7b68d2fea59226 (patch)
tree8171431140a5e84e0d2bdf05861bbca13507266d /ext/readline
parentd2e61d2205e50abe3f834c28618b4db708c5f303 (diff)
* ext/readline/readline.c (readline_getc): applied a patch in
#3827 by by Akio Tajima <artonx AT yahoo.co.jp>. (see #3827) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/readline')
-rw-r--r--ext/readline/readline.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index c08d88b..65c0c41 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -131,6 +131,34 @@ readline_getc(FILE *input)
if (!readline_instream) return rl_getc(input);
GetOpenFile(readline_instream, ifp);
if (rl_instream != ifp->stdio_file) return rl_getc(input);
+#if defined(_WIN32)
+ {
+ 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)) {
+ if (n == 1) {
+ if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) {
+ 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, INFINITE);
+ }
+ } else {
+ break;
+ }
+ }
+ }
+#endif
c = rb_funcall(readline_instream, id_getbyte, 0, 0);
if (NIL_P(c)) return EOF;
return NUM2CHR(c);