Skip to content

Commit 7cba765

Browse files
committed
Added intr: option to IO#raw
Enters raw-mode but enable interrupts.
1 parent 4e17c90 commit 7cba765

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

ext/io/console/console.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ getattr(int fd, conmode *t)
7474
#define SET_LAST_ERROR (0)
7575
#endif
7676

77-
static ID id_getc, id_console, id_close, id_min, id_time;
77+
static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
7878
#if ENABLE_IO_GETPASS
7979
static ID id_gets;
8080
#endif
@@ -101,6 +101,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
101101
typedef struct {
102102
int vmin;
103103
int vtime;
104+
int intr;
104105
} rawmode_arg_t;
105106

106107
static rawmode_arg_t *
@@ -122,9 +123,11 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
122123
if (!NIL_P(vopts)) {
123124
VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
124125
VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
126+
VALUE intr = rb_hash_aref(vopts, ID2SYM(id_intr));
125127
/* default values by `stty raw` */
126128
opts->vmin = 1;
127129
opts->vtime = 0;
130+
opts->intr = 0;
128131
if (!NIL_P(vmin)) {
129132
opts->vmin = NUM2INT(vmin);
130133
optp = opts;
@@ -135,6 +138,21 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
135138
opts->vtime = NUM2INT(vtime);
136139
optp = opts;
137140
}
141+
switch (intr) {
142+
case Qtrue:
143+
opts->intr = 1;
144+
optp = opts;
145+
break;
146+
case Qfalse:
147+
opts->intr = 0;
148+
optp = opts;
149+
break;
150+
case Qnil:
151+
break;
152+
default:
153+
rb_raise(rb_eArgError, "true or false expected as intr: %"PRIsVALUE,
154+
intr);
155+
}
138156
}
139157
return optp;
140158
}
@@ -162,6 +180,10 @@ set_rawmode(conmode *t, void *arg)
162180
const rawmode_arg_t *r = arg;
163181
if (r->vmin >= 0) t->c_cc[VMIN] = r->vmin;
164182
if (r->vtime >= 0) t->c_cc[VTIME] = r->vtime;
183+
if (r->intr) {
184+
t->c_iflag |= BRKINT|IXON;
185+
t->c_lflag |= ISIG|IEXTEN;
186+
}
165187
}
166188
#endif
167189
}
@@ -1382,6 +1404,7 @@ Init_console(void)
13821404
id_close = rb_intern("close");
13831405
id_min = rb_intern("min");
13841406
id_time = rb_intern("time");
1407+
id_intr = rb_intern("intr");
13851408
#ifndef HAVE_RB_F_SEND
13861409
id___send__ = rb_intern("__send__");
13871410
#endif

0 commit comments

Comments
 (0)