1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/io-console] Fixed intr: false mode on Windows

https://github.com/ruby/io-console/commit/4c172c01aa
This commit is contained in:
Nobuyoshi Nakada 2019-12-04 10:06:54 +09:00
parent 447d583536
commit 5a404efd29

View file

@ -175,17 +175,21 @@ set_rawmode(conmode *t, void *arg)
#elif defined _WIN32 #elif defined _WIN32
*t = 0; *t = 0;
#endif #endif
#if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
if (arg) { if (arg) {
const rawmode_arg_t *r = arg; const rawmode_arg_t *r = arg;
#ifdef VMIN
if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin; if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin;
#endif
#ifdef VTIME
if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime; if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime;
#endif
#ifdef ISIG
if (r->intr) { if (r->intr) {
t->c_iflag |= BRKINT|IXON; t->c_iflag |= BRKINT|IXON;
t->c_lflag |= ISIG|IEXTEN; t->c_lflag |= ISIG|IEXTEN;
} }
}
#endif #endif
}
} }
static void static void
@ -449,6 +453,28 @@ getc_call(VALUE io)
{ {
return rb_funcallv(io, id_getc, 0, 0); return rb_funcallv(io, id_getc, 0, 0);
} }
#else
static VALUE
nogvl_getch(void *p)
{
int len = 0;
wint_t *buf = p, c = _getwch();
switch (c) {
case WEOF:
break;
return (VALUE)0;
case 0x00:
case 0xe0:
buf[len++] = c;
c = _getwch();
/* fall through */
default:
buf[len++] = c;
break;
}
return (VALUE)len;
}
#endif #endif
/* /*
@ -473,6 +499,7 @@ console_getch(int argc, VALUE *argv, VALUE io)
wint_t c; wint_t c;
int w, len; int w, len;
char buf[8]; char buf[8];
wint_t wbuf[2];
struct timeval *to = NULL, tv; struct timeval *to = NULL, tv;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
@ -485,24 +512,26 @@ console_getch(int argc, VALUE *argv, VALUE io)
if (optp->vmin != 1) { if (optp->vmin != 1) {
rb_warning("min option ignored"); rb_warning("min option ignored");
} }
if (optp->intr) {
w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
if (w < 0) rb_eof_error();
if (!(w & RB_WAITFD_IN)) return Qnil;
}
} }
w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to); len = (int)rb_thread_io_blocking_region(nogvl_getch, wbuf, fptr->fd);
if (w < 0) rb_eof_error(); switch (len) {
if (!(w & RB_WAITFD_IN)) return Qnil; case 0:
c = _getwch();
switch (c) {
case WEOF:
return Qnil; return Qnil;
case 0x00: case 2:
case 0xe0: buf[0] = (char)wbuf[0];
buf[0] = (char)c; c = wbuf[1];
c = _getwch();
len = 1; len = 1;
do { do {
buf[len++] = (unsigned char)c; buf[len++] = (unsigned char)c;
} while ((c >>= CHAR_BIT) && len < (int)sizeof(buf)); } while ((c >>= CHAR_BIT) && len < (int)sizeof(buf));
return rb_str_new(buf, len); return rb_str_new(buf, len);
default: default:
c = wbuf[0];
len = rb_uv_to_utf8(buf, c); len = rb_uv_to_utf8(buf, c);
str = rb_utf8_str_new(buf, len); str = rb_utf8_str_new(buf, len);
return rb_str_conv_enc(str, NULL, rb_default_external_encoding()); return rb_str_conv_enc(str, NULL, rb_default_external_encoding());