io-console 0.9.2 → 0.9.4
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 +4 -4
- data/ext/io/console/console.c +101 -13
- data/ext/io/console/extconf.rb +27 -2
- data/lib/io/console/size.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 982d948cdd16ab0999b230f5bcd0518e9e45306b4520ca2279d070cd19c545aa
|
|
4
|
+
data.tar.gz: 5b7e540146b2f6ff031a094d8c4b127eae8d16031d9fd14bee1f98b14bd4e531
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ad6916e763a997cb36429a8c5968ece5e24932698560a3e12b1502ddc98478361915ea3b8f673a558c7a1d06355a1ca5ecfd7b5c8b505be73ca1d63c658278a
|
|
7
|
+
data.tar.gz: 07ad02584ba78446e4f959e5fd76fe1b8e1ec48e465c77a4ae14b6538a43567adbc03b2c105115eec84789d56b83b6649fca6b17f9087023fcc11cfdb6f57742
|
data/ext/io/console/console.c
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
static const char *const
|
|
7
|
-
IO_CONSOLE_VERSION = "0.9.
|
|
7
|
+
IO_CONSOLE_VERSION = "0.9.4";
|
|
8
8
|
|
|
9
9
|
#include "ruby.h"
|
|
10
10
|
#include "ruby/io.h"
|
|
@@ -178,6 +178,22 @@ typedef struct {
|
|
|
178
178
|
# define NIL_OR_UNDEF_P(obj) (NIL_P(obj) || UNDEF_P(obj))
|
|
179
179
|
#endif
|
|
180
180
|
|
|
181
|
+
static int
|
|
182
|
+
to_vtime(VALUE vtime)
|
|
183
|
+
{
|
|
184
|
+
VALUE v10 = INT2FIX(10);
|
|
185
|
+
vtime = rb_funcall3(vtime, '*', 1, &v10);
|
|
186
|
+
return NUM2INT(vtime);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static unsigned char
|
|
190
|
+
clamp_uchar(int n)
|
|
191
|
+
{
|
|
192
|
+
if ((unsigned int)n >= UCHAR_MAX) n = UCHAR_MAX;
|
|
193
|
+
else if (n < 0) n = 0;
|
|
194
|
+
return (unsigned char)n;
|
|
195
|
+
}
|
|
196
|
+
|
|
181
197
|
static rawmode_arg_t *
|
|
182
198
|
rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *opts)
|
|
183
199
|
{
|
|
@@ -209,13 +225,11 @@ rawmode_opt(int *argcp, VALUE *argv, int min_argc, int max_argc, rawmode_arg_t *
|
|
|
209
225
|
opts->vtime = 0;
|
|
210
226
|
opts->intr = 0;
|
|
211
227
|
if (!NIL_OR_UNDEF_P(vmin)) {
|
|
212
|
-
opts->vmin = NUM2INT(vmin);
|
|
228
|
+
opts->vmin = clamp_uchar(NUM2INT(vmin));
|
|
213
229
|
optp = opts;
|
|
214
230
|
}
|
|
215
231
|
if (!NIL_OR_UNDEF_P(vtime)) {
|
|
216
|
-
|
|
217
|
-
vtime = rb_funcall3(vtime, '*', 1, &v10);
|
|
218
|
-
opts->vtime = NUM2INT(vtime);
|
|
232
|
+
opts->vtime = clamp_uchar(to_vtime(vtime));
|
|
219
233
|
optp = opts;
|
|
220
234
|
}
|
|
221
235
|
switch (intr) {
|
|
@@ -762,6 +776,13 @@ conmode_init_copy(VALUE obj, VALUE obj2)
|
|
|
762
776
|
return obj;
|
|
763
777
|
}
|
|
764
778
|
|
|
779
|
+
static VALUE
|
|
780
|
+
conmode_get_echo(VALUE obj)
|
|
781
|
+
{
|
|
782
|
+
conmode *t = rb_check_typeddata(obj, &conmode_type);
|
|
783
|
+
return echo_p(t) ? Qtrue : Qfalse;
|
|
784
|
+
}
|
|
785
|
+
|
|
765
786
|
static VALUE
|
|
766
787
|
conmode_set_echo(VALUE obj, VALUE f)
|
|
767
788
|
{
|
|
@@ -794,6 +815,58 @@ conmode_raw_new(int argc, VALUE *argv, VALUE obj)
|
|
|
794
815
|
return conmode_new(rb_obj_class(obj), &t);
|
|
795
816
|
}
|
|
796
817
|
|
|
818
|
+
static VALUE
|
|
819
|
+
conmode_get_min(VALUE obj)
|
|
820
|
+
{
|
|
821
|
+
conmode *t = rb_check_typeddata(obj, &conmode_type);
|
|
822
|
+
#ifdef VMIN
|
|
823
|
+
return INT2FIX(t->c_cc[VMIN]);
|
|
824
|
+
#else
|
|
825
|
+
(void)t;
|
|
826
|
+
return Qnil;
|
|
827
|
+
#endif
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
static VALUE
|
|
831
|
+
conmode_set_min(VALUE obj, VALUE min)
|
|
832
|
+
{
|
|
833
|
+
conmode *t = rb_check_typeddata(obj, &conmode_type);
|
|
834
|
+
int vmin = NIL_P(min) ? 1 : clamp_uchar(NUM2INT(min));
|
|
835
|
+
#ifdef VMIN
|
|
836
|
+
t->c_cc[VMIN] = vmin;
|
|
837
|
+
#else
|
|
838
|
+
(void)t;
|
|
839
|
+
(void)vmin;
|
|
840
|
+
#endif
|
|
841
|
+
return min;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
static VALUE
|
|
845
|
+
conmode_get_time(VALUE obj)
|
|
846
|
+
{
|
|
847
|
+
conmode *t = rb_check_typeddata(obj, &conmode_type);
|
|
848
|
+
#ifdef VTIME
|
|
849
|
+
return rb_rational_new(INT2FIX(t->c_cc[VTIME]), INT2FIX(10));
|
|
850
|
+
#else
|
|
851
|
+
(void)t;
|
|
852
|
+
return Qnil;
|
|
853
|
+
#endif
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
static VALUE
|
|
857
|
+
conmode_set_time(VALUE obj, VALUE time)
|
|
858
|
+
{
|
|
859
|
+
conmode *t = rb_check_typeddata(obj, &conmode_type);
|
|
860
|
+
int vtime = NIL_P(time) ? 0 : clamp_uchar(to_vtime(time));
|
|
861
|
+
#ifdef VTIME
|
|
862
|
+
t->c_cc[VTIME] = vtime;
|
|
863
|
+
#else
|
|
864
|
+
(void)t;
|
|
865
|
+
(void)vtime;
|
|
866
|
+
#endif
|
|
867
|
+
return time;
|
|
868
|
+
}
|
|
869
|
+
|
|
797
870
|
#ifdef _WIN32
|
|
798
871
|
/*
|
|
799
872
|
* call-seq:
|
|
@@ -2135,10 +2208,17 @@ puts_call(VALUE io)
|
|
|
2135
2208
|
return rb_io_write(io, rb_default_rs);
|
|
2136
2209
|
}
|
|
2137
2210
|
|
|
2211
|
+
static VALUE
|
|
2212
|
+
funcall_with_rs(VALUE obj, ID mid)
|
|
2213
|
+
{
|
|
2214
|
+
const VALUE rs = rb_default_rs; /* rvalue in TruffleRuby */
|
|
2215
|
+
return rb_funcallv(obj, mid, 1, &rs);
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2138
2218
|
static VALUE
|
|
2139
2219
|
gets_call(VALUE io)
|
|
2140
2220
|
{
|
|
2141
|
-
return
|
|
2221
|
+
return funcall_with_rs(io, id_gets);
|
|
2142
2222
|
}
|
|
2143
2223
|
|
|
2144
2224
|
static VALUE
|
|
@@ -2161,8 +2241,7 @@ static VALUE
|
|
|
2161
2241
|
str_chomp(VALUE str)
|
|
2162
2242
|
{
|
|
2163
2243
|
if (!NIL_P(str)) {
|
|
2164
|
-
|
|
2165
|
-
rb_funcallv(str, id_chomp_bang, 1, &rs);
|
|
2244
|
+
funcall_with_rs(str, id_chomp_bang);
|
|
2166
2245
|
}
|
|
2167
2246
|
return str;
|
|
2168
2247
|
}
|
|
@@ -2223,7 +2302,7 @@ io_getpass(int argc, VALUE *argv, VALUE io)
|
|
|
2223
2302
|
* call-seq:
|
|
2224
2303
|
* io.ttyname -> string or nil
|
|
2225
2304
|
*
|
|
2226
|
-
* Returns name of associated terminal (tty) if +io+ is
|
|
2305
|
+
* Returns name of associated terminal (tty) if +io+ is a tty.
|
|
2227
2306
|
* Returns +nil+ otherwise.
|
|
2228
2307
|
*/
|
|
2229
2308
|
static VALUE
|
|
@@ -2235,20 +2314,23 @@ console_ttyname(VALUE io)
|
|
|
2235
2314
|
return rb_usascii_str_new_lit("con");
|
|
2236
2315
|
# elif defined HAVE_TTYNAME_R
|
|
2237
2316
|
{
|
|
2317
|
+
# ifdef TTYNAME_R_RETURNS_CHAR_P
|
|
2318
|
+
# define ttyname_r(fd, name, size) (ttyname_r(fd, name, size) == NULL ? errno : 0)
|
|
2319
|
+
# endif
|
|
2238
2320
|
char termname[1024], *tn = termname;
|
|
2239
2321
|
size_t size = sizeof(termname);
|
|
2240
2322
|
int e;
|
|
2241
|
-
if (ttyname_r(fd, tn, size) == 0)
|
|
2323
|
+
if ((e = ttyname_r(fd, tn, size)) == 0)
|
|
2242
2324
|
return rb_interned_str_cstr(tn);
|
|
2243
|
-
if (
|
|
2325
|
+
if (e == ERANGE) {
|
|
2244
2326
|
VALUE s = rb_str_new(0, size);
|
|
2245
2327
|
while (1) {
|
|
2246
2328
|
tn = RSTRING_PTR(s);
|
|
2247
2329
|
size = rb_str_capacity(s);
|
|
2248
|
-
if (ttyname_r(fd, tn, size) == 0) {
|
|
2330
|
+
if ((e = ttyname_r(fd, tn, size)) == 0) {
|
|
2249
2331
|
return rb_str_to_interned_str(rb_str_resize(s, strlen(tn)));
|
|
2250
2332
|
}
|
|
2251
|
-
if (
|
|
2333
|
+
if (e != ERANGE) break;
|
|
2252
2334
|
if ((size *= 2) >= INT_MAX/2) break;
|
|
2253
2335
|
rb_str_resize(s, size);
|
|
2254
2336
|
}
|
|
@@ -2502,9 +2584,15 @@ InitVM_console(void)
|
|
|
2502
2584
|
rb_define_alloc_func(cConmode, conmode_alloc);
|
|
2503
2585
|
rb_undef_method(cConmode, "initialize");
|
|
2504
2586
|
rb_define_method(cConmode, "initialize_copy", conmode_init_copy, 1);
|
|
2587
|
+
rb_define_method(cConmode, "echo?", conmode_get_echo, 0);
|
|
2588
|
+
rb_define_method(cConmode, "echo", conmode_get_echo, 0);
|
|
2505
2589
|
rb_define_method(cConmode, "echo=", conmode_set_echo, 1);
|
|
2506
2590
|
rb_define_method(cConmode, "raw!", conmode_set_raw, -1);
|
|
2507
2591
|
rb_define_method(cConmode, "raw", conmode_raw_new, -1);
|
|
2592
|
+
rb_define_method(cConmode, "min", conmode_get_min, 0);
|
|
2593
|
+
rb_define_method(cConmode, "min=", conmode_set_min, 1);
|
|
2594
|
+
rb_define_method(cConmode, "time", conmode_get_time, 0);
|
|
2595
|
+
rb_define_method(cConmode, "time=", conmode_set_time, 1);
|
|
2508
2596
|
#ifdef _WIN32
|
|
2509
2597
|
rb_define_method(cConmode, "virtual_terminal_processing?", conmode_virtual_terminal_processing_p, 0);
|
|
2510
2598
|
rb_define_method(cConmode, "virtual_terminal_processing=", conmode_set_virtual_terminal_processing, 1);
|
data/ext/io/console/extconf.rb
CHANGED
|
@@ -50,10 +50,35 @@ when true
|
|
|
50
50
|
end
|
|
51
51
|
have_func("rb_category_warn")
|
|
52
52
|
have_const("RB_WARN_CATEGORY_DEPRECATED")
|
|
53
|
-
win32
|
|
53
|
+
unless win32
|
|
54
|
+
if have_func("ttyname_r")
|
|
55
|
+
ret = checking_for("type of ttyname_r()", "%s") {try_link(<<~C) ? "int" : "char *"}
|
|
56
|
+
#{cpp_include %<unistd.h>}
|
|
57
|
+
int t(void) {char name[1024]; return ttyname_r(0, name, sizeof(name)) % 1024;}
|
|
58
|
+
#{MAIN_DOES_NOTHING('t')}
|
|
59
|
+
C
|
|
60
|
+
$defs << "-DTTYNAME_R_RETURNS_#{ret.tr_cpp}"
|
|
61
|
+
else
|
|
62
|
+
have_func("ttyname")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
54
65
|
have_func("rb_prepend_module") # not exported by TruffleRuby
|
|
66
|
+
vk_tool = find_executable("gperf")
|
|
55
67
|
create_makefile("io/console") {|conf|
|
|
56
|
-
conf << "
|
|
68
|
+
conf << "###\n" "all: # the default target\n"
|
|
69
|
+
if vk_header
|
|
70
|
+
conf << <<~MK
|
|
71
|
+
VK_HEADER = #{vk_header}
|
|
72
|
+
console.#$OBJEXT: $(VK_HEADER)
|
|
73
|
+
MK
|
|
74
|
+
end
|
|
75
|
+
if vk_tool and vk_mk = (File.read("#$srcdir/win32_vk.mk") rescue nil)
|
|
76
|
+
unless conf.any? {|c| /^ *top_srcdir *=/.match?(c)}
|
|
77
|
+
conf << "top_srcdir = $(srcdir)/../../..\n"
|
|
78
|
+
end
|
|
79
|
+
conf.concat(depend_rules(vk_mk))
|
|
80
|
+
end
|
|
81
|
+
conf
|
|
57
82
|
}
|
|
58
83
|
when nil
|
|
59
84
|
File.write("Makefile", dummy_makefile($srcdir).join(""))
|
data/lib/io/console/size.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: false
|
|
2
2
|
# fallback to console window size
|
|
3
3
|
def IO.default_console_size
|
|
4
|
+
lines = ENV["LINES"].to_i
|
|
5
|
+
columns = ENV["COLUMNS"].to_i
|
|
4
6
|
[
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
lines.positive? ? lines : 25,
|
|
8
|
+
columns.positive? ? columns : 80,
|
|
7
9
|
]
|
|
8
10
|
end
|
|
9
11
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: io-console
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nobu Nakada
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-09-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: add console capabilities to IO instances.
|
|
13
13
|
email: nobu@ruby-lang.org
|