ruby-changes:57749
From: Nobuyoshi <ko1@a...>
Date: Sat, 14 Sep 2019 23:28:17 +0900 (JST)
Subject: [ruby-changes:57749] 6d2dcf9632 (master): [ruby/io-console] Added `intr:` option to IO#raw
https://git.ruby-lang.org/ruby.git/commit/?id=6d2dcf9632 From 6d2dcf96323189402ea551ed86de6c2766659593 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 14 Sep 2019 22:24:44 +0900 Subject: [ruby/io-console] Added `intr:` option to IO#raw Enters raw-mode but enable interrupts. https://github.com/ruby/io-console/commit/7cba76561a diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 40f1c86..8c698b9 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -74,7 +74,7 @@ getattr(int fd, conmode *t) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L74 #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) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L101 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 * https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L123 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 * https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L138 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) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L180 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) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L1404 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/