io-console 0.5.11 → 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 +30 -10
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a402e8ba6c8522b3b423e828a4575da34a084c97a5e6d27cbed65e35695a9c9e
4
- data.tar.gz: 50fa0e88472bcdd8f3242c3957c8ed7c39d5f6c6f41f3d7db48a0eaf73cc64f2
3
+ metadata.gz: de02d043306e16f29960fa17d759837467ccefd601846e609b4885ea0daa78ff
4
+ data.tar.gz: c856d4c462e9c1ed04c22863b441fc0b2e0802ad9aae0a2a9307d92d3018dd45
5
5
  SHA512:
6
- metadata.gz: 6b190b4fb0d1dedaccc0613754d8c656f65dfa3766ac04624d0a0fd1943339a61aee118beed8be1274de764bfc8404697a303da30300377381d521fbc2d77acf
7
- data.tar.gz: 70a62bd336c53ccd8ae25bacc7bb5a8d7a26d0d5eabcd26ee9541137f8d86345159f134d5f04bde13be0486d057ab7bdbbf2a3667d88b92b6350b6543de12c11
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
@@ -112,18 +112,34 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
112
112
  }
113
113
  #endif
114
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
+
115
123
  typedef struct {
116
124
  int vmin;
117
125
  int vtime;
118
126
  int intr;
119
127
  } rawmode_arg_t;
120
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
+
121
136
  static rawmode_arg_t *
122
137
  rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *opts)
123
138
  {
124
139
  int argc = *argcp;
125
140
  rawmode_arg_t *optp = NULL;
126
141
  VALUE vopts = Qnil;
142
+ VALUE optvals[rawmode_opt_id_count];
127
143
  #ifdef RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
128
144
  argc = rb_scan_args(argc, argv, "*:", NULL, &vopts);
129
145
  #else
@@ -138,19 +154,20 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
138
154
  }
139
155
  #endif
140
156
  rb_check_arity(argc, min_argc, max_argc);
141
- if (!NIL_P(vopts)) {
142
- VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
143
- VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
144
- 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];
145
162
  /* default values by `stty raw` */
146
163
  opts->vmin = 1;
147
164
  opts->vtime = 0;
148
165
  opts->intr = 0;
149
- if (!NIL_P(vmin)) {
166
+ if (!NIL_OR_UNDEF_P(vmin)) {
150
167
  opts->vmin = NUM2INT(vmin);
151
168
  optp = opts;
152
169
  }
153
- if (!NIL_P(vtime)) {
170
+ if (!NIL_OR_UNDEF_P(vtime)) {
154
171
  VALUE v10 = INT2FIX(10);
155
172
  vtime = rb_funcall3(vtime, '*', 1, &v10);
156
173
  opts->vtime = NUM2INT(vtime);
@@ -165,6 +182,7 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
165
182
  opts->intr = 0;
166
183
  optp = opts;
167
184
  break;
185
+ case Qundef:
168
186
  case Qnil:
169
187
  break;
170
188
  default:
@@ -1633,9 +1651,11 @@ Init_console(void)
1633
1651
  #endif
1634
1652
  id_console = rb_intern("console");
1635
1653
  id_close = rb_intern("close");
1636
- id_min = rb_intern("min");
1637
- id_time = rb_intern("time");
1638
- 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);
1639
1659
  #ifndef HAVE_RB_F_SEND
1640
1660
  id___send__ = rb_intern("__send__");
1641
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.11
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-12-29 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
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubygems_version: 3.2.32
47
+ rubygems_version: 3.4.0.dev
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Console interface