io-console 0.9.2 → 0.9.3
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 +98 -13
- data/ext/io/console/extconf.rb +15 -1
- 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: ebd03c00dd26da504baad420ab97511db9bdce9f417d11ae1c22b0d66b900d25
|
|
4
|
+
data.tar.gz: 53d6e1b303c060a5680e1c27b92d20cc5ed218789dc4526cb1f05f89ba006eeb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d822e1e4153d1fc233dc844dcd664df75ca34d892fc909c6266dfcd57b082f9d4d766f39a2b447892f2ab9bd7adaf72b830bd197c2bec37bd34de21cb385180
|
|
7
|
+
data.tar.gz: 2d1a01b63c7076d5c28bbf60824fb2a0528f252db3186946000223e95425e19efd4a0e78153496a0f58f9948e16cd1aeea8b1a28644e7a10dc1eb81aa98745c5
|
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.3";
|
|
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
|
|
@@ -2238,17 +2317,17 @@ console_ttyname(VALUE io)
|
|
|
2238
2317
|
char termname[1024], *tn = termname;
|
|
2239
2318
|
size_t size = sizeof(termname);
|
|
2240
2319
|
int e;
|
|
2241
|
-
if (ttyname_r(fd, tn, size) == 0)
|
|
2320
|
+
if ((e = ttyname_r(fd, tn, size)) == 0)
|
|
2242
2321
|
return rb_interned_str_cstr(tn);
|
|
2243
|
-
if (
|
|
2322
|
+
if (e == ERANGE) {
|
|
2244
2323
|
VALUE s = rb_str_new(0, size);
|
|
2245
2324
|
while (1) {
|
|
2246
2325
|
tn = RSTRING_PTR(s);
|
|
2247
2326
|
size = rb_str_capacity(s);
|
|
2248
|
-
if (ttyname_r(fd, tn, size) == 0) {
|
|
2327
|
+
if ((e = ttyname_r(fd, tn, size)) == 0) {
|
|
2249
2328
|
return rb_str_to_interned_str(rb_str_resize(s, strlen(tn)));
|
|
2250
2329
|
}
|
|
2251
|
-
if (
|
|
2330
|
+
if (e != ERANGE) break;
|
|
2252
2331
|
if ((size *= 2) >= INT_MAX/2) break;
|
|
2253
2332
|
rb_str_resize(s, size);
|
|
2254
2333
|
}
|
|
@@ -2502,9 +2581,15 @@ InitVM_console(void)
|
|
|
2502
2581
|
rb_define_alloc_func(cConmode, conmode_alloc);
|
|
2503
2582
|
rb_undef_method(cConmode, "initialize");
|
|
2504
2583
|
rb_define_method(cConmode, "initialize_copy", conmode_init_copy, 1);
|
|
2584
|
+
rb_define_method(cConmode, "echo?", conmode_get_echo, 0);
|
|
2585
|
+
rb_define_method(cConmode, "echo", conmode_get_echo, 0);
|
|
2505
2586
|
rb_define_method(cConmode, "echo=", conmode_set_echo, 1);
|
|
2506
2587
|
rb_define_method(cConmode, "raw!", conmode_set_raw, -1);
|
|
2507
2588
|
rb_define_method(cConmode, "raw", conmode_raw_new, -1);
|
|
2589
|
+
rb_define_method(cConmode, "min", conmode_get_min, 0);
|
|
2590
|
+
rb_define_method(cConmode, "min=", conmode_set_min, 1);
|
|
2591
|
+
rb_define_method(cConmode, "time", conmode_get_time, 0);
|
|
2592
|
+
rb_define_method(cConmode, "time=", conmode_set_time, 1);
|
|
2508
2593
|
#ifdef _WIN32
|
|
2509
2594
|
rb_define_method(cConmode, "virtual_terminal_processing?", conmode_virtual_terminal_processing_p, 0);
|
|
2510
2595
|
rb_define_method(cConmode, "virtual_terminal_processing=", conmode_set_virtual_terminal_processing, 1);
|
data/ext/io/console/extconf.rb
CHANGED
|
@@ -52,8 +52,22 @@ when true
|
|
|
52
52
|
have_const("RB_WARN_CATEGORY_DEPRECATED")
|
|
53
53
|
win32 or have_func("ttyname_r") or have_func("ttyname")
|
|
54
54
|
have_func("rb_prepend_module") # not exported by TruffleRuby
|
|
55
|
+
vk_tool = find_executable("gperf")
|
|
55
56
|
create_makefile("io/console") {|conf|
|
|
56
|
-
conf << "
|
|
57
|
+
conf << "###\n" "all: # the default target\n"
|
|
58
|
+
if vk_header
|
|
59
|
+
conf << <<~MK
|
|
60
|
+
VK_HEADER = #{vk_header}
|
|
61
|
+
console.#$OBJEXT: $(VK_HEADER)
|
|
62
|
+
MK
|
|
63
|
+
end
|
|
64
|
+
if vk_tool and vk_mk = (File.read("#$srcdir/win32_vk.mk") rescue nil)
|
|
65
|
+
unless conf.any? {|c| /^ *top_srcdir *=/.match?(c)}
|
|
66
|
+
conf << "top_srcdir = $(srcdir)/../../..\n"
|
|
67
|
+
end
|
|
68
|
+
conf.concat(depend_rules(vk_mk))
|
|
69
|
+
end
|
|
70
|
+
conf
|
|
57
71
|
}
|
|
58
72
|
when nil
|
|
59
73
|
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.3
|
|
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-14 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: add console capabilities to IO instances.
|
|
13
13
|
email: nobu@ruby-lang.org
|