io-console 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/io/console/console.c +37 -13
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4124dc490e2ac47dda9ad9283023351e95d781ac40af9a22f012a25c3b3eb15
4
- data.tar.gz: 9ff304d0831ef2d5486f02c5da57fbe91ae960c4d3f1f28057e8e55a7fc7507a
3
+ metadata.gz: de02d043306e16f29960fa17d759837467ccefd601846e609b4885ea0daa78ff
4
+ data.tar.gz: c856d4c462e9c1ed04c22863b441fc0b2e0802ad9aae0a2a9307d92d3018dd45
5
5
  SHA512:
6
- metadata.gz: c8f277a43454e22b0c43beee7eba4069eac9db3b369a4ce0799259d482606a212fbb1d3deae07031703840add83fd5561dfe7170bc62f60675aabf695613e493
7
- data.tar.gz: dfe52d8ca7becd7cf2aa8a27a56702380c1723bfd12393583cff7ad04c2996671b669476d8fd506c3e703d30b75c4084467ffcb8b0fcd7fe6e2be424f9d57c11
6
+ metadata.gz: a1bc386a15fc15532d8c673a3769284f629a44c10402d5a8b9807ab142d1288eb3158ba6dc485f41e4fa9ead0081c180285fad1bc1f27cf6882e41b44ebdbcf0
7
+ data.tar.gz: 6476a4e36be5c0f49ec6ebddbfefb902e15d55fc09f726416bdfb9b781a2c7746504ce06c606fe1573af2cfe0fdb10338a78f1088cc43fcae3b71a133c0e87e9
@@ -75,7 +75,7 @@ getattr(int fd, conmode *t)
75
75
  #define SET_LAST_ERROR (0)
76
76
  #endif
77
77
 
78
- static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
78
+ static ID id_getc, id_console, id_close;
79
79
  #if ENABLE_IO_GETPASS
80
80
  static ID id_gets, id_chomp_bang;
81
81
  #endif
@@ -90,6 +90,10 @@ extern VALUE rb_scheduler_timeout(struct timeval *timeout);
90
90
  #define sys_fail_fptr(fptr) rb_sys_fail_str((fptr)->pathv)
91
91
 
92
92
  #ifndef HAVE_RB_F_SEND
93
+ #ifndef RB_PASS_CALLED_KEYWORDS
94
+ # define rb_funcallv_kw(recv, mid, arg, argv, kw_splat) rb_funcallv(recv, mid, arg, argv)
95
+ #endif
96
+
93
97
  static ID id___send__;
94
98
 
95
99
  static VALUE
@@ -104,22 +108,38 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
104
108
  else {
105
109
  vid = id___send__;
106
110
  }
107
- return rb_funcallv(recv, vid, argc, argv);
111
+ return rb_funcallv_kw(recv, vid, argc, argv, RB_PASS_CALLED_KEYWORDS);
108
112
  }
109
113
  #endif
110
114
 
115
+ enum rawmode_opt_ids {
116
+ kwd_min,
117
+ kwd_time,
118
+ kwd_intr,
119
+ rawmode_opt_id_count
120
+ };
121
+ static ID rawmode_opt_ids[rawmode_opt_id_count];
122
+
111
123
  typedef struct {
112
124
  int vmin;
113
125
  int vtime;
114
126
  int intr;
115
127
  } rawmode_arg_t;
116
128
 
129
+ #ifndef UNDEF_P
130
+ # define UNDEF_P(obj) ((obj) == Qundef)
131
+ #endif
132
+ #ifndef NIL_OR_UNDEF_P
133
+ # define NIL_OR_UNDEF_P(obj) (NIL_P(obj) || UNDEF_P(obj))
134
+ #endif
135
+
117
136
  static rawmode_arg_t *
118
137
  rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *opts)
119
138
  {
120
139
  int argc = *argcp;
121
140
  rawmode_arg_t *optp = NULL;
122
141
  VALUE vopts = Qnil;
142
+ VALUE optvals[rawmode_opt_id_count];
123
143
  #ifdef RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
124
144
  argc = rb_scan_args(argc, argv, "*:", NULL, &vopts);
125
145
  #else
@@ -134,19 +154,20 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
134
154
  }
135
155
  #endif
136
156
  rb_check_arity(argc, min_argc, max_argc);
137
- if (!NIL_P(vopts)) {
138
- VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
139
- VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
140
- VALUE intr = rb_hash_aref(vopts, ID2SYM(id_intr));
157
+ if (rb_get_kwargs(vopts, rawmode_opt_ids,
158
+ 0, rawmode_opt_id_count, optvals)) {
159
+ VALUE vmin = optvals[kwd_min];
160
+ VALUE vtime = optvals[kwd_time];
161
+ VALUE intr = optvals[kwd_intr];
141
162
  /* default values by `stty raw` */
142
163
  opts->vmin = 1;
143
164
  opts->vtime = 0;
144
165
  opts->intr = 0;
145
- if (!NIL_P(vmin)) {
166
+ if (!NIL_OR_UNDEF_P(vmin)) {
146
167
  opts->vmin = NUM2INT(vmin);
147
168
  optp = opts;
148
169
  }
149
- if (!NIL_P(vtime)) {
170
+ if (!NIL_OR_UNDEF_P(vtime)) {
150
171
  VALUE v10 = INT2FIX(10);
151
172
  vtime = rb_funcall3(vtime, '*', 1, &v10);
152
173
  opts->vtime = NUM2INT(vtime);
@@ -161,6 +182,7 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
161
182
  opts->intr = 0;
162
183
  optp = opts;
163
184
  break;
185
+ case Qundef:
164
186
  case Qnil:
165
187
  break;
166
188
  default:
@@ -555,8 +577,8 @@ console_getch(int argc, VALUE *argv, VALUE io)
555
577
  if (w < 0) rb_eof_error();
556
578
  if (!(w & RB_WAITFD_IN)) return Qnil;
557
579
  # else
558
- VALUE result = rb_io_wait(io, RUBY_IO_READABLE, timeout);
559
- if (result == Qfalse) return Qnil;
580
+ VALUE result = rb_io_wait(io, RB_INT2NUM(RUBY_IO_READABLE), timeout);
581
+ if (!RTEST(result)) return Qnil;
560
582
  # endif
561
583
  }
562
584
  else if (optp->vtime) {
@@ -1629,9 +1651,11 @@ Init_console(void)
1629
1651
  #endif
1630
1652
  id_console = rb_intern("console");
1631
1653
  id_close = rb_intern("close");
1632
- id_min = rb_intern("min");
1633
- id_time = rb_intern("time");
1634
- id_intr = rb_intern("intr");
1654
+ #define init_rawmode_opt_id(name) \
1655
+ rawmode_opt_ids[kwd_##name] = rb_intern(#name)
1656
+ init_rawmode_opt_id(min);
1657
+ init_rawmode_opt_id(time);
1658
+ init_rawmode_opt_id(intr);
1635
1659
  #ifndef HAVE_RB_F_SEND
1636
1660
  id___send__ = rb_intern("__send__");
1637
1661
  #endif
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: add console capabilities to IO instances.
14
14
  email: nobu@ruby-lang.org
@@ -37,14 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.4.0
40
+ version: 2.6.0
41
41
  required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubygems_version: 3.2.3
47
+ rubygems_version: 3.4.0.dev
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Console interface