io-console 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/io/console/console.c +61 -28
- data/ext/io/console/extconf.rb +3 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11b22a8d7f56c201a15c12dcd7989f79252c4197c46d145a611fc6e7f21fed6b
|
4
|
+
data.tar.gz: 4421595bf26a904a74167777f8b456438ec0cbb2f7a46314d35a783c48aef3f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed6a2aed986b44ba25be2e04e7867421a5f7f341e5a6c4ef7a06f0d6c5790adfd4d8345005fd755ce75ea3306e73cc809ffe5f85ea3eed7995766b533e90b867
|
7
|
+
data.tar.gz: 64802adccfd88e58df35f30a269999cb685bc6b10d2f7aa715a862d8d7cb2bed985c0778c8e0a0575823c91bea369d4ab5d8703be34269ff8d4e9fbce3865019
|
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
|
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
|
|
data/ext/io/console/console.c
CHANGED
@@ -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
|
|
@@ -410,9 +416,9 @@ console_set_raw(int argc, VALUE *argv, VALUE io)
|
|
410
416
|
|
411
417
|
GetOpenFile(io, fptr);
|
412
418
|
fd = GetReadFD(fptr);
|
413
|
-
if (!getattr(fd, &t))
|
419
|
+
if (!getattr(fd, &t)) sys_fail_fptr(fptr);
|
414
420
|
set_rawmode(&t, optp);
|
415
|
-
if (!setattr(fd, &t))
|
421
|
+
if (!setattr(fd, &t)) sys_fail_fptr(fptr);
|
416
422
|
return io;
|
417
423
|
}
|
418
424
|
|
@@ -453,9 +459,9 @@ console_set_cooked(VALUE io)
|
|
453
459
|
|
454
460
|
GetOpenFile(io, fptr);
|
455
461
|
fd = GetReadFD(fptr);
|
456
|
-
if (!getattr(fd, &t))
|
462
|
+
if (!getattr(fd, &t)) sys_fail_fptr(fptr);
|
457
463
|
set_cookedmode(&t, NULL);
|
458
|
-
if (!setattr(fd, &t))
|
464
|
+
if (!setattr(fd, &t)) sys_fail_fptr(fptr);
|
459
465
|
return io;
|
460
466
|
}
|
461
467
|
|
@@ -508,28 +514,50 @@ console_getch(int argc, VALUE *argv, VALUE io)
|
|
508
514
|
rb_io_t *fptr;
|
509
515
|
VALUE str;
|
510
516
|
wint_t c;
|
511
|
-
int
|
517
|
+
int len;
|
512
518
|
char buf[8];
|
513
519
|
wint_t wbuf[2];
|
520
|
+
# ifndef HAVE_RB_IO_WAIT
|
514
521
|
struct timeval *to = NULL, tv;
|
522
|
+
# else
|
523
|
+
VALUE timeout = Qnil;
|
524
|
+
# endif
|
515
525
|
|
516
526
|
GetOpenFile(io, fptr);
|
517
527
|
if (optp) {
|
518
528
|
if (optp->vtime) {
|
529
|
+
# ifndef HAVE_RB_IO_WAIT
|
519
530
|
to = &tv;
|
531
|
+
# else
|
532
|
+
struct timeval tv;
|
533
|
+
# endif
|
520
534
|
tv.tv_sec = optp->vtime / 10;
|
521
535
|
tv.tv_usec = (optp->vtime % 10) * 100000;
|
536
|
+
# ifdef HAVE_RB_IO_WAIT
|
537
|
+
timeout = rb_scheduler_timeout(&tv);
|
538
|
+
# endif
|
522
539
|
}
|
523
|
-
|
524
|
-
|
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");
|
525
548
|
}
|
526
549
|
if (optp->intr) {
|
527
|
-
|
550
|
+
# ifndef HAVE_RB_IO_WAIT
|
551
|
+
int w = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, to);
|
528
552
|
if (w < 0) rb_eof_error();
|
529
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
|
530
558
|
}
|
531
|
-
else {
|
532
|
-
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");
|
533
561
|
}
|
534
562
|
}
|
535
563
|
len = (int)(VALUE)rb_thread_call_without_gvl(nogvl_getch, wbuf, RUBY_UBF_IO, 0);
|
@@ -590,12 +618,12 @@ console_set_echo(VALUE io, VALUE f)
|
|
590
618
|
|
591
619
|
GetOpenFile(io, fptr);
|
592
620
|
fd = GetReadFD(fptr);
|
593
|
-
if (!getattr(fd, &t))
|
621
|
+
if (!getattr(fd, &t)) sys_fail_fptr(fptr);
|
594
622
|
if (RTEST(f))
|
595
623
|
set_echo(&t, NULL);
|
596
624
|
else
|
597
625
|
set_noecho(&t, NULL);
|
598
|
-
if (!setattr(fd, &t))
|
626
|
+
if (!setattr(fd, &t)) sys_fail_fptr(fptr);
|
599
627
|
return io;
|
600
628
|
}
|
601
629
|
|
@@ -616,7 +644,7 @@ console_echo_p(VALUE io)
|
|
616
644
|
|
617
645
|
GetOpenFile(io, fptr);
|
618
646
|
fd = GetReadFD(fptr);
|
619
|
-
if (!getattr(fd, &t))
|
647
|
+
if (!getattr(fd, &t)) sys_fail_fptr(fptr);
|
620
648
|
return echo_p(&t) ? Qtrue : Qfalse;
|
621
649
|
}
|
622
650
|
|
@@ -700,7 +728,7 @@ console_conmode_get(VALUE io)
|
|
700
728
|
|
701
729
|
GetOpenFile(io, fptr);
|
702
730
|
fd = GetReadFD(fptr);
|
703
|
-
if (!getattr(fd, &t))
|
731
|
+
if (!getattr(fd, &t)) sys_fail_fptr(fptr);
|
704
732
|
|
705
733
|
return conmode_new(cConmode, &t);
|
706
734
|
}
|
@@ -724,7 +752,7 @@ console_conmode_set(VALUE io, VALUE mode)
|
|
724
752
|
r = *t;
|
725
753
|
GetOpenFile(io, fptr);
|
726
754
|
fd = GetReadFD(fptr);
|
727
|
-
if (!setattr(fd, &r))
|
755
|
+
if (!setattr(fd, &r)) sys_fail_fptr(fptr);
|
728
756
|
|
729
757
|
return mode;
|
730
758
|
}
|
@@ -766,7 +794,7 @@ console_winsize(VALUE io)
|
|
766
794
|
|
767
795
|
GetOpenFile(io, fptr);
|
768
796
|
fd = GetWriteFD(fptr);
|
769
|
-
if (!getwinsize(fd, &ws))
|
797
|
+
if (!getwinsize(fd, &ws)) sys_fail_fptr(fptr);
|
770
798
|
return rb_assoc_new(INT2NUM(winsize_row(&ws)), INT2NUM(winsize_col(&ws)));
|
771
799
|
}
|
772
800
|
|
@@ -813,7 +841,7 @@ console_set_winsize(VALUE io, VALUE size)
|
|
813
841
|
SET(xpixel);
|
814
842
|
SET(ypixel);
|
815
843
|
#undef SET
|
816
|
-
if (!setwinsize(fd, &ws))
|
844
|
+
if (!setwinsize(fd, &ws)) sys_fail_fptr(fptr);
|
817
845
|
#elif defined _WIN32
|
818
846
|
wh = (HANDLE)rb_w32_get_osfhandle(fd);
|
819
847
|
#define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m)
|
@@ -888,7 +916,7 @@ console_iflush(VALUE io)
|
|
888
916
|
GetOpenFile(io, fptr);
|
889
917
|
fd = GetReadFD(fptr);
|
890
918
|
#if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
|
891
|
-
if (tcflush(fd, TCIFLUSH))
|
919
|
+
if (tcflush(fd, TCIFLUSH)) sys_fail_fptr(fptr);
|
892
920
|
#endif
|
893
921
|
(void)fd;
|
894
922
|
return io;
|
@@ -911,7 +939,7 @@ console_oflush(VALUE io)
|
|
911
939
|
GetOpenFile(io, fptr);
|
912
940
|
fd = GetWriteFD(fptr);
|
913
941
|
#if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H
|
914
|
-
if (tcflush(fd, TCOFLUSH))
|
942
|
+
if (tcflush(fd, TCOFLUSH)) sys_fail_fptr(fptr);
|
915
943
|
#endif
|
916
944
|
(void)fd;
|
917
945
|
return io;
|
@@ -938,11 +966,11 @@ console_ioflush(VALUE io)
|
|
938
966
|
fd1 = GetReadFD(fptr);
|
939
967
|
fd2 = GetWriteFD(fptr);
|
940
968
|
if (fd2 != -1 && fd1 != fd2) {
|
941
|
-
if (tcflush(fd1, TCIFLUSH))
|
942
|
-
if (tcflush(fd2, TCOFLUSH))
|
969
|
+
if (tcflush(fd1, TCIFLUSH)) sys_fail_fptr(fptr);
|
970
|
+
if (tcflush(fd2, TCOFLUSH)) sys_fail_fptr(fptr);
|
943
971
|
}
|
944
972
|
else {
|
945
|
-
if (tcflush(fd1, TCIOFLUSH))
|
973
|
+
if (tcflush(fd1, TCIOFLUSH)) sys_fail_fptr(fptr);
|
946
974
|
}
|
947
975
|
#endif
|
948
976
|
return io;
|
@@ -961,7 +989,7 @@ console_beep(VALUE io)
|
|
961
989
|
MessageBeep(0);
|
962
990
|
#else
|
963
991
|
if (write(fd, "\a", 1) < 0)
|
964
|
-
|
992
|
+
sys_fail_fptr(fptr);
|
965
993
|
#endif
|
966
994
|
return io;
|
967
995
|
}
|
@@ -1195,8 +1223,8 @@ console_key_pressed_p(VALUE io, VALUE k)
|
|
1195
1223
|
}
|
1196
1224
|
#else
|
1197
1225
|
struct query_args {
|
1198
|
-
|
1199
|
-
|
1226
|
+
char qstr[6];
|
1227
|
+
unsigned char opt;
|
1200
1228
|
};
|
1201
1229
|
|
1202
1230
|
static int
|
@@ -1534,7 +1562,7 @@ static VALUE
|
|
1534
1562
|
str_chomp(VALUE str)
|
1535
1563
|
{
|
1536
1564
|
if (!NIL_P(str)) {
|
1537
|
-
|
1565
|
+
rb_funcallv(str, id_chomp_bang, 0, 0);
|
1538
1566
|
}
|
1539
1567
|
return str;
|
1540
1568
|
}
|
@@ -1546,6 +1574,10 @@ str_chomp(VALUE str)
|
|
1546
1574
|
* Reads and returns a line without echo back.
|
1547
1575
|
* Prints +prompt+ unless it is +nil+.
|
1548
1576
|
*
|
1577
|
+
* The newline character that terminates the
|
1578
|
+
* read line is removed from the returned string,
|
1579
|
+
* see String#chomp!.
|
1580
|
+
*
|
1549
1581
|
* You must require 'io/console' to use this method.
|
1550
1582
|
*/
|
1551
1583
|
static VALUE
|
@@ -1590,6 +1622,7 @@ Init_console(void)
|
|
1590
1622
|
id_getc = rb_intern("getc");
|
1591
1623
|
#if ENABLE_IO_GETPASS
|
1592
1624
|
id_gets = rb_intern("gets");
|
1625
|
+
id_chomp_bang = rb_intern("chomp!");
|
1593
1626
|
#endif
|
1594
1627
|
id_console = rb_intern("console");
|
1595
1628
|
id_close = rb_intern("close");
|
data/ext/io/console/extconf.rb
CHANGED
@@ -24,6 +24,9 @@ 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_func("rb_scheduler_timeout")
|
28
|
+
have_func("rb_io_wait")
|
29
|
+
end
|
27
30
|
$defs << "-D""ENABLE_IO_GETPASS=1"
|
28
31
|
create_makefile("io/console") {|conf|
|
29
32
|
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.
|
4
|
+
version: 0.5.7
|
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:
|
11
|
+
date: 2021-01-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
|
@@ -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
|
@@ -43,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: '0'
|
45
46
|
requirements: []
|
46
|
-
rubygems_version: 3.2.
|
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: []
|