[ruby/io-console] Added intr:
option to IO#raw
Enters raw-mode but enable interrupts. https://github.com/ruby/io-console/commit/7cba76561a
This commit is contained in:
parent
8263459627
commit
6d2dcf9632
Notes:
git
2019-09-14 23:28:19 +09:00
@ -74,7 +74,7 @@ getattr(int fd, conmode *t)
|
|||||||
#define SET_LAST_ERROR (0)
|
#define SET_LAST_ERROR (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static ID id_getc, id_console, id_close, id_min, id_time;
|
static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
|
||||||
#if ENABLE_IO_GETPASS
|
#if ENABLE_IO_GETPASS
|
||||||
static ID id_gets;
|
static ID id_gets;
|
||||||
#endif
|
#endif
|
||||||
@ -101,6 +101,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int vmin;
|
int vmin;
|
||||||
int vtime;
|
int vtime;
|
||||||
|
int intr;
|
||||||
} rawmode_arg_t;
|
} rawmode_arg_t;
|
||||||
|
|
||||||
static rawmode_arg_t *
|
static rawmode_arg_t *
|
||||||
@ -122,9 +123,11 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
|
|||||||
if (!NIL_P(vopts)) {
|
if (!NIL_P(vopts)) {
|
||||||
VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
|
VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
|
||||||
VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
|
VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
|
||||||
|
VALUE intr = rb_hash_aref(vopts, ID2SYM(id_intr));
|
||||||
/* default values by `stty raw` */
|
/* default values by `stty raw` */
|
||||||
opts->vmin = 1;
|
opts->vmin = 1;
|
||||||
opts->vtime = 0;
|
opts->vtime = 0;
|
||||||
|
opts->intr = 0;
|
||||||
if (!NIL_P(vmin)) {
|
if (!NIL_P(vmin)) {
|
||||||
opts->vmin = NUM2INT(vmin);
|
opts->vmin = NUM2INT(vmin);
|
||||||
optp = opts;
|
optp = opts;
|
||||||
@ -135,6 +138,21 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
|
|||||||
opts->vtime = NUM2INT(vtime);
|
opts->vtime = NUM2INT(vtime);
|
||||||
optp = opts;
|
optp = opts;
|
||||||
}
|
}
|
||||||
|
switch (intr) {
|
||||||
|
case Qtrue:
|
||||||
|
opts->intr = 1;
|
||||||
|
optp = opts;
|
||||||
|
break;
|
||||||
|
case Qfalse:
|
||||||
|
opts->intr = 0;
|
||||||
|
optp = opts;
|
||||||
|
break;
|
||||||
|
case Qnil:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eArgError, "true or false expected as intr: %"PRIsVALUE,
|
||||||
|
intr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return optp;
|
return optp;
|
||||||
}
|
}
|
||||||
@ -162,6 +180,10 @@ set_rawmode(conmode *t, void *arg)
|
|||||||
const rawmode_arg_t *r = arg;
|
const rawmode_arg_t *r = arg;
|
||||||
if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin;
|
if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin;
|
||||||
if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime;
|
if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime;
|
||||||
|
if (r->intr) {
|
||||||
|
t->c_iflag |= BRKINT|IXON;
|
||||||
|
t->c_lflag |= ISIG|IEXTEN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1382,6 +1404,7 @@ Init_console(void)
|
|||||||
id_close = rb_intern("close");
|
id_close = rb_intern("close");
|
||||||
id_min = rb_intern("min");
|
id_min = rb_intern("min");
|
||||||
id_time = rb_intern("time");
|
id_time = rb_intern("time");
|
||||||
|
id_intr = rb_intern("intr");
|
||||||
#ifndef HAVE_RB_F_SEND
|
#ifndef HAVE_RB_F_SEND
|
||||||
id___send__ = rb_intern("__send__");
|
id___send__ = rb_intern("__send__");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user