io-console 0.5.0 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfa5eeace30a7b2e59d986f4eaa5ed2bea9f5c2e04aa6b029d7ce59ef28e2c6f
4
- data.tar.gz: c719d7a8e91b4ae909602bacdab03267a341a11430068ba737cc43a79392c63f
3
+ metadata.gz: 823fa2d6014a030a75d08f381bfad31a713e5df4202b627312214b3f0c1d7885
4
+ data.tar.gz: 557347a5cbf21d2a5f8ca52c06c53d774f88905642b2dcd43b176809a1e16d06
5
5
  SHA512:
6
- metadata.gz: bd166f563c0c8cda6ee94eacd6292068e4d681539a6f3ce42872896031634ca944a3b538f6e36232b8227c6d8cf1b95d8a94637c06c83d83a801d0fc347a5a0a
7
- data.tar.gz: 84677613df9260493c5e9ed33e490cf520a21eb50daace16e42503cc7a70885674baa662c015c3f020ba1b076cccba01f75721539d9fec0439751613b8936a0f
6
+ metadata.gz: cd2b8410bc0c0310e6961ff6883c794d672bf6ed1a2898e21ab44383ca863bc54a859931623a33548c120b7830d6309f5bc971f4d5e52777857958893687abcc
7
+ data.tar.gz: fb798eaa2a77a7efa26c433b7481a706f27b020259dc64caa01a87185d755a8078ac63a7987c6b37caf916836d1b8342f7e5bd520cdee5ae921b7e864c08cfed
@@ -4,6 +4,7 @@
4
4
  */
5
5
  #include "ruby.h"
6
6
  #include "ruby/io.h"
7
+ #include "ruby/thread.h"
7
8
 
8
9
  #ifdef HAVE_UNISTD_H
9
10
  #include <unistd.h>
@@ -22,7 +23,7 @@ typedef struct termios conmode;
22
23
  static int
23
24
  setattr(int fd, conmode *t)
24
25
  {
25
- while (tcsetattr(fd, TCSAFLUSH, t)) {
26
+ while (tcsetattr(fd, TCSANOW, t)) {
26
27
  if (errno != EINTR) return 0;
27
28
  }
28
29
  return 1;
@@ -110,6 +111,9 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
110
111
  int argc = *argcp;
111
112
  rawmode_arg_t *optp = NULL;
112
113
  VALUE vopts = Qnil;
114
+ #ifdef RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
115
+ argc = rb_scan_args(argc, argv, "*:", NULL, &vopts);
116
+ #else
113
117
  if (argc > min_argc) {
114
118
  vopts = rb_check_hash_type(argv[argc-1]);
115
119
  if (!NIL_P(vopts)) {
@@ -119,6 +123,7 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
119
123
  if (!vopts) vopts = Qnil;
120
124
  }
121
125
  }
126
+ #endif
122
127
  rb_check_arity(argc, min_argc, max_argc);
123
128
  if (!NIL_P(vopts)) {
124
129
  VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
@@ -164,11 +169,13 @@ set_rawmode(conmode *t, void *arg)
164
169
  cfmakeraw(t);
165
170
  t->c_lflag &= ~(ECHOE|ECHOK);
166
171
  #elif defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
167
- t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
172
+ t->c_iflag &= ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF|IXANY|IMAXBEL);
168
173
  t->c_oflag &= ~OPOST;
169
- t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN);
174
+ t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|XCASE);
170
175
  t->c_cflag &= ~(CSIZE|PARENB);
171
176
  t->c_cflag |= CS8;
177
+ t->c_cc[VMIN] = 1;
178
+ t->c_cc[VTIME] = 0;
172
179
  #elif defined HAVE_SGTTY_H
173
180
  t->sg_flags &= ~ECHO;
174
181
  t->sg_flags |= RAW;
@@ -185,10 +192,12 @@ set_rawmode(conmode *t, void *arg)
185
192
  #endif
186
193
  #ifdef ISIG
187
194
  if (r->intr) {
188
- t->c_iflag |= BRKINT|IXON;
189
- t->c_lflag |= ISIG|IEXTEN;
195
+ t->c_iflag |= BRKINT;
196
+ t->c_lflag |= ISIG;
197
+ t->c_oflag |= OPOST;
190
198
  }
191
199
  #endif
200
+ (void)r;
192
201
  }
193
202
  }
194
203
 
@@ -351,9 +360,9 @@ ttymode_with_io(VALUE io, VALUE (*func)(VALUE, VALUE), VALUE farg, void (*setter
351
360
 
352
361
  /*
353
362
  * call-seq:
354
- * io.raw(min: nil, time: nil) {|io| }
363
+ * io.raw(min: nil, time: nil, intr: nil) {|io| }
355
364
  *
356
- * Yields +self+ within raw mode.
365
+ * Yields +self+ within raw mode, and returns the result of the block.
357
366
  *
358
367
  * STDIN.raw(&:gets)
359
368
  *
@@ -365,6 +374,9 @@ ttymode_with_io(VALUE io, VALUE (*func)(VALUE, VALUE), VALUE farg, void (*setter
365
374
  * The parameter +time+ specifies the timeout in _seconds_ with a
366
375
  * precision of 1/10 of a second. (default: 0)
367
376
  *
377
+ * If the parameter +intr+ is +true+, enables break, interrupt, quit,
378
+ * and suspend special characters.
379
+ *
368
380
  * Refer to the manual page of termios for further details.
369
381
  *
370
382
  * You must require 'io/console' to use this method.
@@ -378,11 +390,11 @@ console_raw(int argc, VALUE *argv, VALUE io)
378
390
 
379
391
  /*
380
392
  * call-seq:
381
- * io.raw!(min: nil, time: nil)
393
+ * io.raw!(min: nil, time: nil, intr: nil) -> io
382
394
  *
383
- * Enables raw mode.
395
+ * Enables raw mode, and returns +io+.
384
396
  *
385
- * If the terminal mode needs to be back, use io.raw { ... }.
397
+ * If the terminal mode needs to be back, use <code>io.raw { ... }</code>.
386
398
  *
387
399
  * See IO#raw for details on the parameters.
388
400
  *
@@ -454,7 +466,7 @@ getc_call(VALUE io)
454
466
  return rb_funcallv(io, id_getc, 0, 0);
455
467
  }
456
468
  #else
457
- static VALUE
469
+ static void *
458
470
  nogvl_getch(void *p)
459
471
  {
460
472
  int len = 0;
@@ -463,7 +475,6 @@ nogvl_getch(void *p)
463
475
  switch (c) {
464
476
  case WEOF:
465
477
  break;
466
- return (VALUE)0;
467
478
  case 0x00:
468
479
  case 0xe0:
469
480
  buf[len++] = c;
@@ -473,13 +484,13 @@ nogvl_getch(void *p)
473
484
  buf[len++] = c;
474
485
  break;
475
486
  }
476
- return (VALUE)len;
487
+ return (void *)(VALUE)len;
477
488
  }
478
489
  #endif
479
490
 
480
491
  /*
481
492
  * call-seq:
482
- * io.getch(min: nil, time: nil) -> char
493
+ * io.getch(min: nil, time: nil, intr: nil) -> char
483
494
  *
484
495
  * Reads and returns a character in raw mode.
485
496
  *
@@ -517,8 +528,11 @@ console_getch(int argc, VALUE *argv, VALUE io)
517
528
  if (w < 0) rb_eof_error();
518
529
  if (!(w & RB_WAITFD_IN)) return Qnil;
519
530
  }
531
+ else {
532
+ rb_warning("vtime option ignored if intr flag is unset");
533
+ }
520
534
  }
521
- len = (int)rb_thread_io_blocking_region(nogvl_getch, wbuf, fptr->fd);
535
+ len = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getch, wbuf, RUBY_UBF_IO, 0);
522
536
  switch (len) {
523
537
  case 0:
524
538
  return Qnil;
@@ -1483,7 +1497,7 @@ console_dev(int argc, VALUE *argv, VALUE klass)
1483
1497
 
1484
1498
  /*
1485
1499
  * call-seq:
1486
- * io.getch(min: nil, time: nil) -> char
1500
+ * io.getch(min: nil, time: nil, intr: nil) -> char
1487
1501
  *
1488
1502
  * See IO#getch.
1489
1503
  */
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
3
 
4
- ok = true
4
+ ok = true if RUBY_ENGINE == "ruby"
5
5
  hdr = nil
6
6
  case
7
7
  when macro_defined?("_WIN32", "")
@@ -14,8 +14,9 @@ when have_header(hdr = "sgtty.h")
14
14
  %w"stty gtty".each {|f| have_func(f, hdr)}
15
15
  else
16
16
  ok = false
17
- end
18
- if ok
17
+ end if ok
18
+ case ok
19
+ when true
19
20
  have_header("sys/ioctl.h") if hdr
20
21
  # rb_check_hash_type: 1.9.3
21
22
  # rb_io_get_write_io: 1.9.1
@@ -27,4 +28,6 @@ if ok
27
28
  create_makefile("io/console") {|conf|
28
29
  conf << "\n""VK_HEADER = #{vk_header}\n"
29
30
  }
31
+ when nil
32
+ File.write("Makefile", dummy_makefile($srcdir).join(""))
30
33
  end
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.0
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: add console capabilities to IO instances.
14
14
  email: nobu@ruby-lang.org
@@ -36,14 +36,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 2.2.0
39
+ version: 2.4.0
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.1.0.pre3
46
+ rubygems_version: 3.2.0.pre1
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: Console interface