diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-14 22:24:44 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-14 23:27:53 +0900 |
commit | 6d2dcf96323189402ea551ed86de6c2766659593 (patch) | |
tree | fdf8beceaffef1c1794e97b3c2b27854bd6c0562 /ext | |
parent | 8263459627b20d4383978b3d1471298bf52bde05 (diff) | |
download | ruby-6d2dcf96323189402ea551ed86de6c2766659593.tar.gz |
[ruby/io-console] Added `intr:` option to IO#raw
Enters raw-mode but enable interrupts.
https://github.com/ruby/io-console/commit/7cba76561a
Diffstat (limited to 'ext')
-rw-r--r-- | ext/io/console/console.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 40f1c861e1..8c698b9b5f 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -74,7 +74,7 @@ getattr(int fd, conmode *t) #define SET_LAST_ERROR (0) #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 static ID id_gets; #endif @@ -101,6 +101,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv) typedef struct { int vmin; int vtime; + int intr; } 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)) { VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min)); VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time)); + VALUE intr = rb_hash_aref(vopts, ID2SYM(id_intr)); /* default values by `stty raw` */ opts->vmin = 1; opts->vtime = 0; + opts->intr = 0; if (!NIL_P(vmin)) { opts->vmin = NUM2INT(vmin); 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); 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; } @@ -162,6 +180,10 @@ set_rawmode(conmode *t, void *arg) const rawmode_arg_t *r = arg; if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin; if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime; + if (r->intr) { + t->c_iflag |= BRKINT|IXON; + t->c_lflag |= ISIG|IEXTEN; + } } #endif } @@ -1382,6 +1404,7 @@ Init_console(void) id_close = rb_intern("close"); id_min = rb_intern("min"); id_time = rb_intern("time"); + id_intr = rb_intern("intr"); #ifndef HAVE_RB_F_SEND id___send__ = rb_intern("__send__"); #endif |