io-console 0.5.6 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823fa2d6014a030a75d08f381bfad31a713e5df4202b627312214b3f0c1d7885
4
- data.tar.gz: 557347a5cbf21d2a5f8ca52c06c53d774f88905642b2dcd43b176809a1e16d06
3
+ metadata.gz: a402e8ba6c8522b3b423e828a4575da34a084c97a5e6d27cbed65e35695a9c9e
4
+ data.tar.gz: 50fa0e88472bcdd8f3242c3957c8ed7c39d5f6c6f41f3d7db48a0eaf73cc64f2
5
5
  SHA512:
6
- metadata.gz: cd2b8410bc0c0310e6961ff6883c794d672bf6ed1a2898e21ab44383ca863bc54a859931623a33548c120b7830d6309f5bc971f4d5e52777857958893687abcc
7
- data.tar.gz: fb798eaa2a77a7efa26c433b7481a706f27b020259dc64caa01a87185d755a8078ac63a7987c6b37caf916836d1b8342f7e5bd520cdee5ae921b7e864c08cfed
6
+ metadata.gz: 6b190b4fb0d1dedaccc0613754d8c656f65dfa3766ac04624d0a0fd1943339a61aee118beed8be1274de764bfc8404697a303da30300377381d521fbc2d77acf
7
+ data.tar.gz: 70a62bd336c53ccd8ae25bacc7bb5a8d7a26d0d5eabcd26ee9541137f8d86345159f134d5f04bde13be0486d057ab7bdbbf2a3667d88b92b6350b6543de12c11
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,10 +77,23 @@ 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
+ #if defined HAVE_RUBY_FIBER_SCHEDULER_H
84
+ # include "ruby/fiber/scheduler.h"
85
+ #elif defined HAVE_RB_SCHEDULER_TIMEOUT
86
+ extern VALUE rb_scheduler_timeout(struct timeval *timeout);
87
+ # define rb_fiber_scheduler_make_timeout rb_scheduler_timeout
88
+ #endif
89
+
90
+ #define sys_fail_fptr(fptr) rb_sys_fail_str((fptr)->pathv)
91
+
83
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
+
84
97
  static ID id___send__;
85
98
 
86
99
  static VALUE
@@ -95,7 +108,7 @@ rb_f_send(int argc, VALUE *argv, VALUE recv)
95
108
  else {
96
109
  vid = id___send__;
97
110
  }
98
- return rb_funcallv(recv, vid, argc, argv);
111
+ return rb_funcallv_kw(recv, vid, argc, argv, RB_PASS_CALLED_KEYWORDS);
99
112
  }
100
113
  #endif
101
114
 
@@ -410,9 +423,9 @@ console_set_raw(int argc, VALUE *argv, VALUE io)
410
423
 
411
424
  GetOpenFile(io, fptr);
412
425
  fd = GetReadFD(fptr);
413
- if (!getattr(fd, &t)) rb_sys_fail(0);
426
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
414
427
  set_rawmode(&t, optp);
415
- if (!setattr(fd, &t)) rb_sys_fail(0);
428
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
416
429
  return io;
417
430
  }
418
431
 
@@ -453,9 +466,9 @@ console_set_cooked(VALUE io)
453
466
 
454
467
  GetOpenFile(io, fptr);
455
468
  fd = GetReadFD(fptr);
456
- if (!getattr(fd, &t)) rb_sys_fail(0);
469
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
457
470
  set_cookedmode(&t, NULL);
458
- if (!setattr(fd, &t)) rb_sys_fail(0);
471
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
459
472
  return io;
460
473
  }
461
474
 
@@ -508,28 +521,50 @@ console_getch(int argc, VALUE *argv, VALUE io)
508
521
  rb_io_t *fptr;
509
522
  VALUE str;
510
523
  wint_t c;
511
- int w, len;
524
+ int len;
512
525
  char buf[8];
513
526
  wint_t wbuf[2];
527
+ # ifndef HAVE_RB_IO_WAIT
514
528
  struct timeval *to = NULL, tv;
529
+ # else
530
+ VALUE timeout = Qnil;
531
+ # endif
515
532
 
516
533
  GetOpenFile(io, fptr);
517
534
  if (optp) {
518
535
  if (optp->vtime) {
536
+ # ifndef HAVE_RB_IO_WAIT
519
537
  to = &tv;
538
+ # else
539
+ struct timeval tv;
540
+ # endif
520
541
  tv.tv_sec = optp->vtime / 10;
521
542
  tv.tv_usec = (optp->vtime % 10) * 100000;
543
+ # ifdef HAVE_RB_IO_WAIT
544
+ timeout = rb_fiber_scheduler_make_timeout(&tv);
545
+ # endif
522
546
  }
523
- if (optp->vmin != 1) {
524
- rb_warning("min option ignored");
547
+ switch (optp->vmin) {
548
+ case 1: /* default */
549
+ break;
550
+ case 0: /* return nil when timed out */
551
+ if (optp->vtime) break;
552
+ /* fallthru */
553
+ default:
554
+ rb_warning("min option larger than 1 ignored");
525
555
  }
526
556
  if (optp->intr) {
527
- w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
557
+ # ifndef HAVE_RB_IO_WAIT
558
+ int w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
528
559
  if (w < 0) rb_eof_error();
529
560
  if (!(w & RB_WAITFD_IN)) return Qnil;
561
+ # else
562
+ VALUE result = rb_io_wait(io, RB_INT2NUM(RUBY_IO_READABLE), timeout);
563
+ if (!RTEST(result)) return Qnil;
564
+ # endif
530
565
  }
531
- else {
532
- rb_warning("vtime option ignored if intr flag is unset");
566
+ else if (optp->vtime) {
567
+ rb_warning("Non-zero vtime option ignored if intr flag is unset");
533
568
  }
534
569
  }
535
570
  len = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getch, wbuf, RUBY_UBF_IO, 0);
@@ -590,12 +625,12 @@ console_set_echo(VALUE io, VALUE f)
590
625
 
591
626
  GetOpenFile(io, fptr);
592
627
  fd = GetReadFD(fptr);
593
- if (!getattr(fd, &t)) rb_sys_fail(0);
628
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
594
629
  if (RTEST(f))
595
630
  set_echo(&t, NULL);
596
631
  else
597
632
  set_noecho(&t, NULL);
598
- if (!setattr(fd, &t)) rb_sys_fail(0);
633
+ if (!setattr(fd, &t)) sys_fail_fptr(fptr);
599
634
  return io;
600
635
  }
601
636
 
@@ -616,7 +651,7 @@ console_echo_p(VALUE io)
616
651
 
617
652
  GetOpenFile(io, fptr);
618
653
  fd = GetReadFD(fptr);
619
- if (!getattr(fd, &t)) rb_sys_fail(0);
654
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
620
655
  return echo_p(&t) ? Qtrue : Qfalse;
621
656
  }
622
657
 
@@ -700,7 +735,7 @@ console_conmode_get(VALUE io)
700
735
 
701
736
  GetOpenFile(io, fptr);
702
737
  fd = GetReadFD(fptr);
703
- if (!getattr(fd, &t)) rb_sys_fail(0);
738
+ if (!getattr(fd, &t)) sys_fail_fptr(fptr);
704
739
 
705
740
  return conmode_new(cConmode, &t);
706
741
  }
@@ -724,7 +759,7 @@ console_conmode_set(VALUE io, VALUE mode)
724
759
  r = *t;
725
760
  GetOpenFile(io, fptr);
726
761
  fd = GetReadFD(fptr);
727
- if (!setattr(fd, &r)) rb_sys_fail(0);
762
+ if (!setattr(fd, &r)) sys_fail_fptr(fptr);
728
763
 
729
764
  return mode;
730
765
  }
@@ -766,7 +801,7 @@ console_winsize(VALUE io)
766
801
 
767
802
  GetOpenFile(io, fptr);
768
803
  fd = GetWriteFD(fptr);
769
- if (!getwinsize(fd, &ws)) rb_sys_fail(0);
804
+ if (!getwinsize(fd, &ws)) sys_fail_fptr(fptr);
770
805
  return rb_assoc_new(INT2NUM(winsize_row(&ws)), INT2NUM(winsize_col(&ws)));
771
806
  }
772
807
 
@@ -813,7 +848,7 @@ console_set_winsize(VALUE io, VALUE size)
813
848
  SET(xpixel);
814
849
  SET(ypixel);
815
850
  #undef SET
816
- if (!setwinsize(fd, &ws)) rb_sys_fail(0);
851
+ if (!setwinsize(fd, &ws)) sys_fail_fptr(fptr);
817
852
  #elif defined _WIN32
818
853
  wh = (HANDLE)rb_w32_get_osfhandle(fd);
819
854
  #define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
@@ -888,7 +923,7 @@ console_iflush(VALUE io)
888
923
  GetOpenFile(io, fptr);
889
924
  fd = GetReadFD(fptr);
890
925
  #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
891
- if (tcflush(fd, TCIFLUSH)) rb_sys_fail(0);
926
+ if (tcflush(fd, TCIFLUSH)) sys_fail_fptr(fptr);
892
927
  #endif
893
928
  (void)fd;
894
929
  return io;
@@ -911,7 +946,7 @@ console_oflush(VALUE io)
911
946
  GetOpenFile(io, fptr);
912
947
  fd = GetWriteFD(fptr);
913
948
  #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
914
- if (tcflush(fd, TCOFLUSH)) rb_sys_fail(0);
949
+ if (tcflush(fd, TCOFLUSH)) sys_fail_fptr(fptr);
915
950
  #endif
916
951
  (void)fd;
917
952
  return io;
@@ -938,11 +973,11 @@ console_ioflush(VALUE io)
938
973
  fd1 = GetReadFD(fptr);
939
974
  fd2 = GetWriteFD(fptr);
940
975
  if (fd2 != -1 && fd1 != fd2) {
941
- if (tcflush(fd1, TCIFLUSH)) rb_sys_fail(0);
942
- if (tcflush(fd2, TCOFLUSH)) rb_sys_fail(0);
976
+ if (tcflush(fd1, TCIFLUSH)) sys_fail_fptr(fptr);
977
+ if (tcflush(fd2, TCOFLUSH)) sys_fail_fptr(fptr);
943
978
  }
944
979
  else {
945
- if (tcflush(fd1, TCIOFLUSH)) rb_sys_fail(0);
980
+ if (tcflush(fd1, TCIOFLUSH)) sys_fail_fptr(fptr);
946
981
  }
947
982
  #endif
948
983
  return io;
@@ -961,7 +996,7 @@ console_beep(VALUE io)
961
996
  MessageBeep(0);
962
997
  #else
963
998
  if (write(fd, "\a", 1) < 0)
964
- rb_sys_fail(0);
999
+ sys_fail_fptr(fptr);
965
1000
  #endif
966
1001
  return io;
967
1002
  }
@@ -1195,8 +1230,8 @@ console_key_pressed_p(VALUE io, VALUE k)
1195
1230
  }
1196
1231
  #else
1197
1232
  struct query_args {
1198
- const char *qstr;
1199
- int opt;
1233
+ char qstr[6];
1234
+ unsigned char opt;
1200
1235
  };
1201
1236
 
1202
1237
  static int
@@ -1534,7 +1569,7 @@ static VALUE
1534
1569
  str_chomp(VALUE str)
1535
1570
  {
1536
1571
  if (!NIL_P(str)) {
1537
- str = rb_funcallv(str, rb_intern("chomp!"), 0, 0);
1572
+ rb_funcallv(str, id_chomp_bang, 0, 0);
1538
1573
  }
1539
1574
  return str;
1540
1575
  }
@@ -1546,6 +1581,10 @@ str_chomp(VALUE str)
1546
1581
  * Reads and returns a line without echo back.
1547
1582
  * Prints +prompt+ unless it is +nil+.
1548
1583
  *
1584
+ * The newline character that terminates the
1585
+ * read line is removed from the returned string,
1586
+ * see String#chomp!.
1587
+ *
1549
1588
  * You must require 'io/console' to use this method.
1550
1589
  */
1551
1590
  static VALUE
@@ -1590,6 +1629,7 @@ Init_console(void)
1590
1629
  id_getc = rb_intern("getc");
1591
1630
  #if ENABLE_IO_GETPASS
1592
1631
  id_gets = rb_intern("gets");
1632
+ id_chomp_bang = rb_intern("chomp!");
1593
1633
  #endif
1594
1634
  id_console = rb_intern("console");
1595
1635
  id_close = rb_intern("close");
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
3
 
4
- ok = true if RUBY_ENGINE == "ruby"
4
+ ok = true if RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
5
5
  hdr = nil
6
6
  case
7
7
  when macro_defined?("_WIN32", "")
@@ -24,6 +24,11 @@ when true
24
24
  # rb_funcallv: 2.1.0
25
25
  # RARRAY_CONST_PTR: 2.1.0
26
26
  # rb_sym2str: 2.2.0
27
+ if have_macro("HAVE_RUBY_FIBER_SCHEDULER_H")
28
+ $defs << "-D""HAVE_RB_IO_WAIT=1"
29
+ elsif have_func("rb_scheduler_timeout") # 3.0
30
+ have_func("rb_io_wait")
31
+ end
27
32
  $defs << "-D""ENABLE_IO_GETPASS=1"
28
33
  create_makefile("io/console") {|conf|
29
34
  conf << "\n""VK_HEADER = #{vk_header}\n"
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.6
4
+ version: 0.5.11
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: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2021-12-29 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.4.0
40
+ version: 2.6.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.2.0.pre1
47
- signing_key:
47
+ rubygems_version: 3.2.32
48
+ signing_key:
48
49
  specification_version: 4
49
50
  summary: Console interface
50
51
  test_files: []