@@ -74,7 +74,7 @@ getattr(int fd, conmode *t)
74
74
#define SET_LAST_ERROR (0)
75
75
#endif
76
76
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 ;
78
78
#if ENABLE_IO_GETPASS
79
79
static ID id_gets ;
80
80
#endif
@@ -101,6 +101,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
101
101
typedef struct {
102
102
int vmin ;
103
103
int vtime ;
104
+ int intr ;
104
105
} rawmode_arg_t ;
105
106
106
107
static rawmode_arg_t *
@@ -122,9 +123,11 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
122
123
if (!NIL_P (vopts )) {
123
124
VALUE vmin = rb_hash_aref (vopts , ID2SYM (id_min ));
124
125
VALUE vtime = rb_hash_aref (vopts , ID2SYM (id_time ));
126
+ VALUE intr = rb_hash_aref (vopts , ID2SYM (id_intr ));
125
127
/* default values by `stty raw` */
126
128
opts -> vmin = 1 ;
127
129
opts -> vtime = 0 ;
130
+ opts -> intr = 0 ;
128
131
if (!NIL_P (vmin )) {
129
132
opts -> vmin = NUM2INT (vmin );
130
133
optp = opts ;
@@ -135,6 +138,21 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
135
138
opts -> vtime = NUM2INT (vtime );
136
139
optp = opts ;
137
140
}
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
+ }
138
156
}
139
157
return optp ;
140
158
}
@@ -162,6 +180,10 @@ set_rawmode(conmode *t, void *arg)
162
180
const rawmode_arg_t * r = arg ;
163
181
if (r -> vmin >= 0 ) t -> c_cc [VMIN ] = r -> vmin ;
164
182
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
+ }
165
187
}
166
188
#endif
167
189
}
@@ -1382,6 +1404,7 @@ Init_console(void)
1382
1404
id_close = rb_intern ("close" );
1383
1405
id_min = rb_intern ("min" );
1384
1406
id_time = rb_intern ("time" );
1407
+ id_intr = rb_intern ("intr" );
1385
1408
#ifndef HAVE_RB_F_SEND
1386
1409
id___send__ = rb_intern ("__send__" );
1387
1410
#endif
0 commit comments