io-console 0.7.1-java → 0.8.0.beta1-java
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/.document +1 -0
- data/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/lib/ffi/io/console/bsd_console.rb +6 -0
- data/lib/ffi/io/console/common.rb +116 -0
- data/lib/ffi/io/console/linux_console.rb +4 -2
- data/lib/ffi/io/console/native_console.rb +2 -115
- data/lib/ffi/io/console/stty_console.rb +33 -22
- data/lib/ffi/io/console/stub_console.rb +1 -1
- data/lib/ffi/io/console/version.rb +1 -1
- data/lib/ffi/io/console.rb +2 -2
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '070823def2bf48e4fd8e7c6e025b8c5eb5a43472ae505cf04d19eb1a9cb7ff58'
|
4
|
+
data.tar.gz: 0a93067f420e9cd95a267b9ea807d08f77b64ba2527f5d850fec23e810abca9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06e6dd0a561c6b3a3b058ffbd003f52bae1e953fc63c8fb79422dd03cbc30ef51074d2dbd4abc0c528db0135086bc2f965fb186ad2ebfc35f00a392f18d113f3
|
7
|
+
data.tar.gz: 929a7573f8397564ab77894c6c998498bee58b7dc9c90e9cdc0af1457a1723668a302f383c60b0f9dd806c65fe582afa9692201cd91d0db53f969c64681bfb89
|
data/.document
CHANGED
data/{LICENSE.txt → BSDL}
RENAMED
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
4
4
|
modification, are permitted provided that the following conditions
|
5
5
|
are met:
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
11
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
13
|
+
make them Freely Available, such as by posting said
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
15
|
+
the author to include your modifications in the software.
|
16
|
+
|
17
|
+
b. use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c. give non-standard binaries non-standard names, with
|
21
|
+
instructions on where to get the original software distribution.
|
22
|
+
|
23
|
+
d. make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or binary form,
|
26
|
+
provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a. distribute the binaries and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent)
|
30
|
+
on where to get the original distribution.
|
31
|
+
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
33
|
+
the software.
|
34
|
+
|
35
|
+
c. give non-standard binaries non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d. make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under these terms.
|
43
|
+
|
44
|
+
For the list of those files and their copying conditions, see the
|
45
|
+
file LEGAL.
|
46
|
+
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
48
|
+
output from the software do not automatically fall under the
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
51
|
+
software.
|
52
|
+
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
56
|
+
PURPOSE.
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
|
3
|
+
tested_platforms = %w[i386 x86_64]
|
4
|
+
|
5
|
+
if RbConfig::CONFIG['host_os'].downcase =~ /darwin/ && FFI::Platform::ARCH !~ /#{tested_platforms.join('|')}/
|
6
|
+
raise LoadError.new("native console on MacOS only supported on #{tested_platforms.join(', ')}")
|
7
|
+
end
|
8
|
+
|
3
9
|
module IO::LibC
|
4
10
|
extend FFI::Library
|
5
11
|
ffi_lib FFI::Library::LIBC
|
@@ -1,5 +1,47 @@
|
|
1
1
|
# Methods common to all backend impls
|
2
2
|
class IO
|
3
|
+
# TODO: Windows version uses "conin$" and "conout$" instead of /dev/tty
|
4
|
+
def self.console(sym = nil, *args)
|
5
|
+
raise TypeError, "expected Symbol, got #{sym.class}" unless sym.nil? || sym.kind_of?(Symbol)
|
6
|
+
|
7
|
+
# klass = self == IO ? File : self
|
8
|
+
if defined?(@console) # using ivar instead of hidden const as in MRI
|
9
|
+
con = @console
|
10
|
+
# MRI checks IO internals : (!RB_TYPE_P(con, T_FILE) || (!(fptr = RFILE(con)->fptr) || GetReadFD(fptr) == -1))
|
11
|
+
if !con.kind_of?(File) || (con.kind_of?(IO) && (con.closed? || !FileTest.readable?(con)))
|
12
|
+
remove_instance_variable :@console
|
13
|
+
con = nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if sym
|
18
|
+
if sym == :close
|
19
|
+
if con
|
20
|
+
con.close
|
21
|
+
remove_instance_variable :@console if defined?(@console)
|
22
|
+
end
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if !con
|
28
|
+
if $stdin.isatty && $stdout.isatty
|
29
|
+
begin
|
30
|
+
con = File.open('/dev/tty', 'r+')
|
31
|
+
rescue
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
|
35
|
+
con.sync = true
|
36
|
+
end
|
37
|
+
|
38
|
+
@console = con
|
39
|
+
end
|
40
|
+
|
41
|
+
return con.send(sym, *args) if sym
|
42
|
+
return con
|
43
|
+
end
|
44
|
+
|
3
45
|
def getch(*, **opts)
|
4
46
|
raw(**opts) do
|
5
47
|
getc
|
@@ -20,6 +62,80 @@ class IO
|
|
20
62
|
str.chomp
|
21
63
|
end
|
22
64
|
|
65
|
+
def cursor
|
66
|
+
raw do
|
67
|
+
syswrite "\e[6n"
|
68
|
+
|
69
|
+
return nil if getbyte != 0x1b
|
70
|
+
return nil if getbyte != ?[.ord
|
71
|
+
|
72
|
+
num = 0
|
73
|
+
result = []
|
74
|
+
|
75
|
+
while b = getbyte
|
76
|
+
c = b.to_i
|
77
|
+
if c == ?;.ord
|
78
|
+
result.push num
|
79
|
+
num = 0
|
80
|
+
elsif c >= ?0.ord && c <= ?9.ord
|
81
|
+
num = num * 10 + c - ?0.ord
|
82
|
+
#elsif opt && c == opt
|
83
|
+
else
|
84
|
+
last = c
|
85
|
+
result.push num
|
86
|
+
b = last.chr
|
87
|
+
return nil unless b == ?R
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
result.map(&:pred)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def cursor=(pos)
|
97
|
+
pos = pos.to_ary if !pos.kind_of?(Array)
|
98
|
+
|
99
|
+
raise "expected 2D coordinates" unless pos.size == 2
|
100
|
+
|
101
|
+
x, y = pos
|
102
|
+
syswrite(format("\x1b[%d;%dH", x + 1, y + 1))
|
103
|
+
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def cursor_down(n)
|
108
|
+
raw do
|
109
|
+
syswrite "\x1b[#{n}B"
|
110
|
+
end
|
111
|
+
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
def cursor_right(n)
|
116
|
+
raw do
|
117
|
+
syswrite "\x1b[#{n}C"
|
118
|
+
end
|
119
|
+
|
120
|
+
self
|
121
|
+
end
|
122
|
+
|
123
|
+
def cursor_left(n)
|
124
|
+
raw do
|
125
|
+
syswrite "\x1b[#{n}D"
|
126
|
+
end
|
127
|
+
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
def cursor_up(n)
|
132
|
+
raw do
|
133
|
+
syswrite "\x1b[#{n}A"
|
134
|
+
end
|
135
|
+
|
136
|
+
self
|
137
|
+
end
|
138
|
+
|
23
139
|
module GenericReadable
|
24
140
|
def getch(*)
|
25
141
|
getc
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
tested_platforms = %w[i386 x86_64 powerpc64 aarch64 s390x]
|
4
|
+
|
5
|
+
unless FFI::Platform::ARCH =~ /#{tested_platforms.join('|')}/
|
6
|
+
warn "native console only tested on #{tested_platforms.join(', ')}"
|
5
7
|
end
|
6
8
|
|
7
9
|
module IO::LibC
|
@@ -52,8 +52,8 @@ class IO
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def raw(*,
|
56
|
-
ttymode_yield(block,
|
55
|
+
def raw(*, min: 1, time: nil, intr: nil, &block)
|
56
|
+
ttymode_yield(block, min:, time:, intr:, &TTY_RAW)
|
57
57
|
end
|
58
58
|
|
59
59
|
def raw!(*)
|
@@ -137,117 +137,4 @@ class IO
|
|
137
137
|
def ioflush
|
138
138
|
raise SystemCallError.new("tcflush(TCIOFLUSH)", FFI.errno) unless LibC.tcflush(self.fileno, LibC::TCIOFLUSH) == 0
|
139
139
|
end
|
140
|
-
|
141
|
-
def cursor
|
142
|
-
raw do
|
143
|
-
syswrite "\e[6n"
|
144
|
-
|
145
|
-
return nil if getbyte != 0x1b
|
146
|
-
return nil if getbyte != ?[.ord
|
147
|
-
|
148
|
-
num = 0
|
149
|
-
result = []
|
150
|
-
|
151
|
-
while b = getbyte
|
152
|
-
c = b.to_i
|
153
|
-
if c == ?;.ord
|
154
|
-
result.push num
|
155
|
-
num = 0
|
156
|
-
elsif c >= ?0.ord && c <= ?9.ord
|
157
|
-
num = num * 10 + c - ?0.ord
|
158
|
-
#elsif opt && c == opt
|
159
|
-
else
|
160
|
-
last = c
|
161
|
-
result.push num
|
162
|
-
b = last.chr
|
163
|
-
return nil unless b == ?R
|
164
|
-
break
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
result.map(&:pred)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def cursor=(pos)
|
173
|
-
pos = pos.to_ary if !pos.kind_of?(Array)
|
174
|
-
|
175
|
-
raise "expected 2D coordinates" unless pos.size == 2
|
176
|
-
|
177
|
-
x, y = pos
|
178
|
-
syswrite(format("\x1b[%d;%dH", x + 1, y + 1))
|
179
|
-
|
180
|
-
self
|
181
|
-
end
|
182
|
-
|
183
|
-
def cursor_down(n)
|
184
|
-
raw do
|
185
|
-
syswrite "\x1b[#{n}B"
|
186
|
-
end
|
187
|
-
|
188
|
-
self
|
189
|
-
end
|
190
|
-
|
191
|
-
def cursor_right(n)
|
192
|
-
raw do
|
193
|
-
syswrite "\x1b[#{n}C"
|
194
|
-
end
|
195
|
-
|
196
|
-
self
|
197
|
-
end
|
198
|
-
|
199
|
-
def cursor_left(n)
|
200
|
-
raw do
|
201
|
-
syswrite "\x1b[#{n}D"
|
202
|
-
end
|
203
|
-
|
204
|
-
self
|
205
|
-
end
|
206
|
-
|
207
|
-
def cursor_up(n)
|
208
|
-
raw do
|
209
|
-
syswrite "\x1b[#{n}A"
|
210
|
-
end
|
211
|
-
|
212
|
-
self
|
213
|
-
end
|
214
|
-
|
215
|
-
# TODO: Windows version uses "conin$" and "conout$" instead of /dev/tty
|
216
|
-
def self.console(sym = nil, *args)
|
217
|
-
raise TypeError, "expected Symbol, got #{sym.class}" unless sym.nil? || sym.kind_of?(Symbol)
|
218
|
-
|
219
|
-
# klass = self == IO ? File : self
|
220
|
-
if defined?(@console) # using ivar instead of hidden const as in MRI
|
221
|
-
con = @console
|
222
|
-
# MRI checks IO internals : (!RB_TYPE_P(con, T_FILE) || (!(fptr = RFILE(con)->fptr) || GetReadFD(fptr) == -1))
|
223
|
-
if !con.kind_of?(File) || (con.kind_of?(IO) && (con.closed? || !FileTest.readable?(con)))
|
224
|
-
remove_instance_variable :@console
|
225
|
-
con = nil
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
if sym
|
230
|
-
if sym == :close
|
231
|
-
if con
|
232
|
-
con.close
|
233
|
-
remove_instance_variable :@console if defined?(@console)
|
234
|
-
end
|
235
|
-
return nil
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
if !con
|
240
|
-
begin
|
241
|
-
con = File.open('/dev/tty', 'r+')
|
242
|
-
rescue
|
243
|
-
return nil
|
244
|
-
end
|
245
|
-
|
246
|
-
con.sync = true
|
247
|
-
@console = con
|
248
|
-
end
|
249
|
-
|
250
|
-
return con.send(sym, *args) if sym
|
251
|
-
return con
|
252
|
-
end
|
253
140
|
end
|
@@ -4,26 +4,39 @@ if $?.exitstatus != 0
|
|
4
4
|
raise "stty command returned nonzero exit status"
|
5
5
|
end
|
6
6
|
|
7
|
-
warn "io/console on JRuby shells out to stty for most operations"
|
7
|
+
warn "io/console on JRuby shells out to stty for most operations" if $VERBOSE
|
8
8
|
|
9
9
|
# Non-Windows assumes stty command is available
|
10
10
|
class IO
|
11
11
|
if RbConfig::CONFIG['host_os'].downcase =~ /linux/ && File.exists?("/proc/#{Process.pid}/fd")
|
12
|
-
def
|
13
|
-
`stty #{args.join(' ')} < /proc/#{Process.pid}/fd/#{fileno}`
|
12
|
+
protected def _io_console_stty(*args)
|
13
|
+
_io_console_stty_error { `stty #{args.join(' ')} < /proc/#{Process.pid}/fd/#{fileno}` }
|
14
14
|
end
|
15
15
|
else
|
16
|
-
def
|
17
|
-
`stty #{args.join(' ')}`
|
16
|
+
protected def _io_console_stty(*args)
|
17
|
+
_io_console_stty_error { `stty #{args.join(' ')}` }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
21
|
+
protected def _io_console_stty_error
|
22
|
+
# pre-check to catch non-tty filenos we can't stty against anyway
|
23
|
+
raise Errno::ENOTTY, inspect if !tty?
|
24
|
+
|
25
|
+
result = yield
|
26
|
+
|
27
|
+
case result
|
28
|
+
when /Inappropriate ioctl for device/
|
29
|
+
raise Errno.ENOTTY, inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw(*, min: 1, time: nil, intr: nil)
|
36
|
+
saved = _io_console_stty('-g raw')
|
24
37
|
yield self
|
25
38
|
ensure
|
26
|
-
|
39
|
+
_io_console_stty(saved)
|
27
40
|
end
|
28
41
|
|
29
42
|
def raw!(*)
|
@@ -31,31 +44,29 @@ class IO
|
|
31
44
|
end
|
32
45
|
|
33
46
|
def cooked(*)
|
34
|
-
saved =
|
35
|
-
stty('-raw')
|
47
|
+
saved = _io_console_stty('-g', '-raw')
|
36
48
|
yield self
|
37
49
|
ensure
|
38
|
-
|
50
|
+
_io_console_stty(saved)
|
39
51
|
end
|
40
52
|
|
41
53
|
def cooked!(*)
|
42
|
-
|
54
|
+
_io_console_stty('-raw')
|
43
55
|
end
|
44
56
|
|
45
57
|
def echo=(echo)
|
46
|
-
|
58
|
+
_io_console_stty(echo ? 'echo' : '-echo')
|
47
59
|
end
|
48
60
|
|
49
61
|
def echo?
|
50
|
-
(
|
62
|
+
(_io_console_stty('-a') =~ / -echo /) ? false : true
|
51
63
|
end
|
52
64
|
|
53
65
|
def noecho
|
54
|
-
saved =
|
55
|
-
stty('-echo')
|
66
|
+
saved = _io_console_stty('-g', '-echo')
|
56
67
|
yield self
|
57
68
|
ensure
|
58
|
-
|
69
|
+
_io_console_stty(saved)
|
59
70
|
end
|
60
71
|
|
61
72
|
# Not all systems return same format of stty -a output
|
@@ -63,7 +74,7 @@ class IO
|
|
63
74
|
UBUNTU = 'rows (?<rows>\d+); columns (?<columns>\d+)'
|
64
75
|
|
65
76
|
def winsize
|
66
|
-
match =
|
77
|
+
match = _io_console_stty('-a').match(/#{IEEE_STD_1003_2}|#{UBUNTU}/)
|
67
78
|
[match[:rows].to_i, match[:columns].to_i]
|
68
79
|
end
|
69
80
|
|
@@ -75,13 +86,13 @@ class IO
|
|
75
86
|
raise ArgumentError.new("wrong number of arguments (given #{sizelen}, expected 2 or 4)")
|
76
87
|
end
|
77
88
|
|
78
|
-
row, col, xpixel, ypixel = size
|
79
|
-
|
80
89
|
if sizelen == 4
|
81
90
|
warn "stty io/console does not support pixel winsize"
|
82
91
|
end
|
83
92
|
|
84
|
-
|
93
|
+
row, col, _, _ = size
|
94
|
+
|
95
|
+
_io_console_stty("rows #{row} cols #{col}")
|
85
96
|
end
|
86
97
|
|
87
98
|
def iflush
|
data/lib/ffi/io/console.rb
CHANGED
@@ -52,9 +52,9 @@ else
|
|
52
52
|
require_relative 'console/stty_console'
|
53
53
|
ready = true
|
54
54
|
|
55
|
-
rescue Exception
|
55
|
+
rescue Exception => ex2
|
56
56
|
|
57
|
-
warn "failed to load stty console support: #{
|
57
|
+
warn "failed to load stty console support: #{ex2}" if $VERBOSE
|
58
58
|
ready = false
|
59
59
|
|
60
60
|
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.
|
4
|
+
version: 0.8.0.beta1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: add console capabilities to IO instances.
|
14
14
|
email: nobu@ruby-lang.org
|
@@ -17,7 +17,8 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- ".document"
|
20
|
-
-
|
20
|
+
- BSDL
|
21
|
+
- COPYING
|
21
22
|
- README.md
|
22
23
|
- lib/ffi/io/console.rb
|
23
24
|
- lib/ffi/io/console/bsd_console.rb
|
@@ -34,7 +35,8 @@ licenses:
|
|
34
35
|
- BSD-2-Clause
|
35
36
|
metadata:
|
36
37
|
source_code_url: https://github.com/ruby/io-console
|
37
|
-
|
38
|
+
changelog_uri: https://github.com/ruby/io-console/releases
|
39
|
+
post_install_message:
|
38
40
|
rdoc_options: []
|
39
41
|
require_paths:
|
40
42
|
- lib/ffi
|
@@ -50,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
52
|
- !ruby/object:Gem::Version
|
51
53
|
version: '0'
|
52
54
|
requirements: []
|
53
|
-
rubygems_version: 3.5.
|
54
|
-
signing_key:
|
55
|
+
rubygems_version: 3.5.11
|
56
|
+
signing_key:
|
55
57
|
specification_version: 4
|
56
58
|
summary: Console interface
|
57
59
|
test_files: []
|