io-console 0.5.3 → 0.5.8

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: 9474fd3d0f8b7760a83e50da0e69ba4e018e96935018a22b933a3f9eec648a5b
4
- data.tar.gz: dc4f448e975155e39360f95f4442f1c54e067821183e6214e5fd2a5475504879
3
+ metadata.gz: decdf097b0ff0dfc69754156a1cb766b68b45fc5007bb845b38e15c6b4190230
4
+ data.tar.gz: f8c2f4ccc7aa3fcc4ad95467a752e313cb86e2473ff2356ccf01ee792d3e7315
5
5
  SHA512:
6
- metadata.gz: 7734614638324ebd6fdf96518d897ebb3e497fae56f5be84d2fbf5098a14923c19445166ccacfa4fcfcdc0a4ea9bdef5c16e627416f44b0d1a7ac93e06b8c073
7
- data.tar.gz: 8bd122615986429eba3668a56e420a5a242c7d80617b8960566426a99f85c56b80fa5089eb5078016aec36cc5b548a49d7ec44e52699555847e06380359dd36d
6
+ metadata.gz: e1bd8dab05ec7e64ee220b39be6aa5429796f6c179b1ac6b300a91cce69469b8e3785d7bc03ab97eb2c22b88e21da1674891fd1574c0cc9affc69a2b084c0f33
7
+ data.tar.gz: 9a8445e54933da15df523fb6dc71670b0ab6c9db4e2fcc2c39ae9df4b4be6887bf590410e722e96caa21858cac753e0b3d330645f7745392b2f91bfab8c7ad4d
data/README.md CHANGED
@@ -27,7 +27,7 @@ IO.console -> #<File:/dev/tty>
27
27
  IO.console(sym, *args)
28
28
  ```
29
29
 
30
- Returns an File instance opened console.
30
+ Returns a File instance opened console.
31
31
 
32
32
  If `sym` is given, it will be sent to the opened console with `args` and the result will be returned instead of the console IO itself.
33
33
 
@@ -1,4 +1,4 @@
1
- /* -*- c-file-style: "ruby" -*- */
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: t -*- */
2
2
  /*
3
3
  * console IO module
4
4
  */
@@ -77,9 +77,15 @@ getattr(int fd, conmode *t)
77
77
 
78
78
  static ID id_getc, id_console, id_close, id_min, id_time, id_intr;
79
79
  #if ENABLE_IO_GETPASS
80
- static ID id_gets;
80
+ static ID id_gets, id_chomp_bang;
81
81
  #endif
82
82
 
83
+ #ifdef HAVE_RB_SCHEDULER_TIMEOUT
84
+ extern VALUE rb_scheduler_timeout(struct timeval *timeout);
85
+ #endif
86
+
87
+ #define sys_fail_fptr(fptr) rb_sys_fail_str((fptr)->pathv)
88
+
83
89
  #ifndef HAVE_RB_F_SEND
84
90
  static ID id___send__;
85
91
 
@@ -111,6 +117,9 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
111
117
  int argc = *argcp;
112
118
  rawmode_arg_t *optp = NULL;
113
119
  VALUE vopts = Qnil;
120
+ #ifdef RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
121
+ argc = rb_scan_args(argc, argv, "*:", NULL, &vopts);
122
+ #else
114
123
  if (argc > min_argc) {
115
124
  vopts = rb_check_hash_type(argv[argc-1]);
116
125
  if (!NIL_P(vopts)) {
@@ -120,6 +129,7 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
120
129
  if (!vopts) vopts = Qnil;
121
130
  }
122
131
  }
132
+ #endif
123
133
  rb_check_arity(argc, min_argc, max_argc);
124
134
  if (!NIL_P(vopts)) {
125
135
  VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
@@ -188,8 +198,9 @@ set_rawmode(conmode *t, void *arg)
188
198
  #endif
189
199
  #ifdef ISIG
190
200
  if (r->intr) {
191
- t->c_iflag |= BRKINT|IXON;
201
+ t->c_iflag |= BRKINT;
192
202
  t->c_lflag |= ISIG;
203
+ t->c_oflag |= OPOST;
193
204
  }
194
205
  #endif
195
206
  (void)r;
@@ -355,9 +366,9 @@ ttymode_with_io(VALUE io, VALUE (*func)(VALUE, VALUE), VALUE farg, void (*setter
355
366
 
356
367
  /*
357
368
  * call-seq:
358
- * io.raw(min: nil, time: nil) {|io| }
369
+ * io.raw(min: nil, time: nil, intr: nil) {|io| }
359
370
  *
360
- * Yields +self+ within raw mode.
371
+ * Yields +self+ within raw mode, and returns the result of the block.
361
372
  *
362
373
  * STDIN.raw(&:gets)
363
374
  *
@@ -369,6 +380,9 @@ ttymode_with_io(VALUE io, VALUE (*func)(VALUE, VALUE), VALUE farg, void (*setter
369
380
  * The parameter +time+ specifies the timeout in _seconds_ with a
370
381
  * precision of 1/10 of a second. (default: 0)
371
382
  *
383
+ * If the parameter +intr+ is +true+, enables break, interrupt, quit,
384
+ * and suspend special characters.
385
+ *
372
386
  * Refer to the manual page of termios for further details.
373
387
  *
374
388
  * You must require 'io/console' to use this method.
@@ -382,11 +396,11 @@ console_raw(int argc, VALUE *argv, VALUE io)
382
396
 
383
397
  /*
384
398
  * call-seq:
385
- * io.raw!(min: nil, time: nil)
399
+ * io.raw!(min: nil, time: nil, intr: nil) -> io
386
400
  *
387
- * Enables raw mode.
401
+ * Enables raw mode, and returns +io+.
388
402
  *
389
- * If the terminal mode needs to be back, use io.raw { ... }.
403
+ * If the terminal mode needs to be back, use <code>io.raw { ... }</code>.
390
404
  *
391
405
  * See IO#raw for details on the parameters.
392
406
  *
@@ -402,9 +416,9 @@ console_set_raw(int argc, VALUE *argv, VALUE io)
402
416
 
403
417
  GetOpenFile(io, fptr);
404
418
  fd = GetReadFD(fptr);
405
- if (!getattr(fd, &t)) rb_sys_fail(0);
419
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
406
420
  set_rawmode(&t, optp);
407
- if (!setattr(fd, &t)) rb_sys_fail(0);
421
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
408
422
  return io;
409
423
  }
410
424
 
@@ -445,9 +459,9 @@ console_set_cooked(VALUE io)
445
459
 
446
460
  GetOpenFile(io, fptr);
447
461
  fd = GetReadFD(fptr);
448
- if (!getattr(fd, &t)) rb_sys_fail(0);
462
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
449
463
  set_cookedmode(&t, NULL);
450
- if (!setattr(fd, &t)) rb_sys_fail(0);
464
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
451
465
  return io;
452
466
  }
453
467
 
@@ -482,7 +496,7 @@ nogvl_getch(void *p)
482
496
 
483
497
  /*
484
498
  * call-seq:
485
- * io.getch(min: nil, time: nil) -> char
499
+ * io.getch(min: nil, time: nil, intr: nil) -> char
486
500
  *
487
501
  * Reads and returns a character in raw mode.
488
502
  *
@@ -500,28 +514,50 @@ console_getch(int argc, VALUE *argv, VALUE io)
500
514
  rb_io_t *fptr;
501
515
  VALUE str;
502
516
  wint_t c;
503
- int w, len;
517
+ int len;
504
518
  char buf[8];
505
519
  wint_t wbuf[2];
520
+ # ifndef HAVE_RB_IO_WAIT
506
521
  struct timeval *to = NULL, tv;
522
+ # else
523
+ VALUE timeout = Qnil;
524
+ # endif
507
525
 
508
526
  GetOpenFile(io, fptr);
509
527
  if (optp) {
510
528
  if (optp->vtime) {
529
+ # ifndef HAVE_RB_IO_WAIT
511
530
  to = &tv;
531
+ # else
532
+ struct timeval tv;
533
+ # endif
512
534
  tv.tv_sec = optp->vtime / 10;
513
535
  tv.tv_usec = (optp->vtime % 10) * 100000;
536
+ # ifdef HAVE_RB_IO_WAIT
537
+ timeout = rb_scheduler_timeout(&tv);
538
+ # endif
514
539
  }
515
- if (optp->vmin != 1) {
516
- rb_warning("min option ignored");
540
+ switch (optp->vmin) {
541
+ case 1: /* default */
542
+ break;
543
+ case 0: /* return nil when timed out */
544
+ if (optp->vtime) break;
545
+ /* fallthru */
546
+ default:
547
+ rb_warning("min option larger than 1 ignored");
517
548
  }
518
549
  if (optp->intr) {
519
- w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
550
+ # ifndef HAVE_RB_IO_WAIT
551
+ int w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
520
552
  if (w < 0) rb_eof_error();
521
553
  if (!(w & RB_WAITFD_IN)) return Qnil;
554
+ # else
555
+ VALUE result = rb_io_wait(io, RUBY_IO_READABLE, timeout);
556
+ if (result == Qfalse) return Qnil;
557
+ # endif
522
558
  }
523
- else {
524
- rb_warning("vtime option ignored if intr flag is unset");
559
+ else if (optp->vtime) {
560
+ rb_warning("Non-zero vtime option ignored if intr flag is unset");
525
561
  }
526
562
  }
527
563
  len = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getch, wbuf, RUBY_UBF_IO, 0);
@@ -582,12 +618,12 @@ console_set_echo(VALUE io, VALUE f)
582
618
 
583
619
  GetOpenFile(io, fptr);
584
620
  fd = GetReadFD(fptr);
585
- if (!getattr(fd, &t)) rb_sys_fail(0);
621
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
586
622
  if (RTEST(f))
587
623
  set_echo(&t, NULL);
588
624
  else
589
625
  set_noecho(&t, NULL);
590
- if (!setattr(fd, &t)) rb_sys_fail(0);
626
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
591
627
  return io;
592
628
  }
593
629
 
@@ -608,7 +644,7 @@ console_echo_p(VALUE io)
608
644
 
609
645
  GetOpenFile(io, fptr);
610
646
  fd = GetReadFD(fptr);
611
- if (!getattr(fd, &t)) rb_sys_fail(0);
647
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
612
648
  return echo_p(&t) ? Qtrue : Qfalse;
613
649
  }
614
650
 
@@ -692,7 +728,7 @@ console_conmode_get(VALUE io)
692
728
 
693
729
  GetOpenFile(io, fptr);
694
730
  fd = GetReadFD(fptr);
695
- if (!getattr(fd, &t)) rb_sys_fail(0);
731
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
696
732
 
697
733
  return conmode_new(cConmode, &t);
698
734
  }
@@ -716,7 +752,7 @@ console_conmode_set(VALUE io, VALUE mode)
716
752
  r = *t;
717
753
  GetOpenFile(io, fptr);
718
754
  fd = GetReadFD(fptr);
719
- if (!setattr(fd, &r)) rb_sys_fail(0);
755
+ if (!setattr(fd, &r)) sys_fail_fptr(fptr);
720
756
 
721
757
  return mode;
722
758
  }
@@ -758,7 +794,7 @@ console_winsize(VALUE io)
758
794
 
759
795
  GetOpenFile(io, fptr);
760
796
  fd = GetWriteFD(fptr);
761
- if (!getwinsize(fd, &ws)) rb_sys_fail(0);
797
+ if (!getwinsize(fd, &ws)) sys_fail_fptr(fptr);
762
798
  return rb_assoc_new(INT2NUM(winsize_row(&ws)), INT2NUM(winsize_col(&ws)));
763
799
  }
764
800
 
@@ -805,7 +841,7 @@ console_set_winsize(VALUE io, VALUE size)
805
841
  SET(xpixel);
806
842
  SET(ypixel);
807
843
  #undef SET
808
- if (!setwinsize(fd, &ws)) rb_sys_fail(0);
844
+ if (!setwinsize(fd, &ws)) sys_fail_fptr(fptr);
809
845
  #elif defined _WIN32
810
846
  wh = (HANDLE)rb_w32_get_osfhandle(fd);
811
847
  #define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
@@ -880,7 +916,7 @@ console_iflush(VALUE io)
880
916
  GetOpenFile(io, fptr);
881
917
  fd = GetReadFD(fptr);
882
918
  #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
883
- if (tcflush(fd, TCIFLUSH)) rb_sys_fail(0);
919
+ if (tcflush(fd, TCIFLUSH)) sys_fail_fptr(fptr);
884
920
  #endif
885
921
  (void)fd;
886
922
  return io;
@@ -903,7 +939,7 @@ console_oflush(VALUE io)
903
939
  GetOpenFile(io, fptr);
904
940
  fd = GetWriteFD(fptr);
905
941
  #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
906
- if (tcflush(fd, TCOFLUSH)) rb_sys_fail(0);
942
+ if (tcflush(fd, TCOFLUSH)) sys_fail_fptr(fptr);
907
943
  #endif
908
944
  (void)fd;
909
945
  return io;
@@ -930,11 +966,11 @@ console_ioflush(VALUE io)
930
966
  fd1 = GetReadFD(fptr);
931
967
  fd2 = GetWriteFD(fptr);
932
968
  if (fd2 != -1 && fd1 != fd2) {
933
- if (tcflush(fd1, TCIFLUSH)) rb_sys_fail(0);
934
- if (tcflush(fd2, TCOFLUSH)) rb_sys_fail(0);
969
+ if (tcflush(fd1, TCIFLUSH)) sys_fail_fptr(fptr);
970
+ if (tcflush(fd2, TCOFLUSH)) sys_fail_fptr(fptr);
935
971
  }
936
972
  else {
937
- if (tcflush(fd1, TCIOFLUSH)) rb_sys_fail(0);
973
+ if (tcflush(fd1, TCIOFLUSH)) sys_fail_fptr(fptr);
938
974
  }
939
975
  #endif
940
976
  return io;
@@ -953,7 +989,7 @@ console_beep(VALUE io)
953
989
  MessageBeep(0);
954
990
  #else
955
991
  if (write(fd, "\a", 1) < 0)
956
- rb_sys_fail(0);
992
+ sys_fail_fptr(fptr);
957
993
  #endif
958
994
  return io;
959
995
  }
@@ -1187,8 +1223,8 @@ console_key_pressed_p(VALUE io, VALUE k)
1187
1223
  }
1188
1224
  #else
1189
1225
  struct query_args {
1190
- const char *qstr;
1191
- int opt;
1226
+ char qstr[6];
1227
+ unsigned char opt;
1192
1228
  };
1193
1229
 
1194
1230
  static int
@@ -1489,7 +1525,7 @@ console_dev(int argc, VALUE *argv, VALUE klass)
1489
1525
 
1490
1526
  /*
1491
1527
  * call-seq:
1492
- * io.getch(min: nil, time: nil) -> char
1528
+ * io.getch(min: nil, time: nil, intr: nil) -> char
1493
1529
  *
1494
1530
  * See IO#getch.
1495
1531
  */
@@ -1526,7 +1562,7 @@ static VALUE
1526
1562
  str_chomp(VALUE str)
1527
1563
  {
1528
1564
  if (!NIL_P(str)) {
1529
- str = rb_funcallv(str, rb_intern("chomp!"), 0, 0);
1565
+ rb_funcallv(str, id_chomp_bang, 0, 0);
1530
1566
  }
1531
1567
  return str;
1532
1568
  }
@@ -1538,6 +1574,10 @@ str_chomp(VALUE str)
1538
1574
  * Reads and returns a line without echo back.
1539
1575
  * Prints +prompt+ unless it is +nil+.
1540
1576
  *
1577
+ * The newline character that terminates the
1578
+ * read line is removed from the returned string,
1579
+ * see String#chomp!.
1580
+ *
1541
1581
  * You must require 'io/console' to use this method.
1542
1582
  */
1543
1583
  static VALUE
@@ -1582,6 +1622,7 @@ Init_console(void)
1582
1622
  id_getc = rb_intern("getc");
1583
1623
  #if ENABLE_IO_GETPASS
1584
1624
  id_gets = rb_intern("gets");
1625
+ id_chomp_bang = rb_intern("chomp!");
1585
1626
  #endif
1586
1627
  id_console = rb_intern("console");
1587
1628
  id_close = rb_intern("close");
@@ -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
@@ -23,8 +24,13 @@ if ok
23
24
  # rb_funcallv: 2.1.0
24
25
  # RARRAY_CONST_PTR: 2.1.0
25
26
  # rb_sym2str: 2.2.0
27
+ if have_func("rb_scheduler_timeout")
28
+ have_func("rb_io_wait")
29
+ end
26
30
  $defs << "-D""ENABLE_IO_GETPASS=1"
27
31
  create_makefile("io/console") {|conf|
28
32
  conf << "\n""VK_HEADER = #{vk_header}\n"
29
33
  }
34
+ when nil
35
+ File.write("Makefile", dummy_makefile($srcdir).join(""))
30
36
  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.3
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-25 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: add console capabilities to IO instances.
14
14
  email: nobu@ruby-lang.org
@@ -25,10 +25,11 @@ files:
25
25
  - lib/io/console/size.rb
26
26
  homepage: https://github.com/ruby/io-console
27
27
  licenses:
28
+ - Ruby
28
29
  - BSD-2-Clause
29
30
  metadata:
30
31
  source_code_url: https://github.com/ruby/io-console
31
- post_install_message:
32
+ post_install_message:
32
33
  rdoc_options: []
33
34
  require_paths:
34
35
  - lib
@@ -36,15 +37,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
37
  requirements:
37
38
  - - ">="
38
39
  - !ruby/object:Gem::Version
39
- version: 2.2.0
40
+ version: 2.4.0
40
41
  required_rubygems_version: !ruby/object:Gem::Requirement
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  requirements: []
46
- rubygems_version: 3.1.1
47
- signing_key:
47
+ rubygems_version: 3.2.3
48
+ signing_key:
48
49
  specification_version: 4
49
50
  summary: Console interface
50
51
  test_files: []