io-console 0.5.7-java → 0.5.8-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/io/console.rb +5 -0
- data/{jruby/io/console → lib/io/console/ffi}/bsd_console.rb +1 -1
- data/{jruby/io/console → lib/io/console/ffi}/common.rb +2 -2
- data/{jruby/io → lib/io/console/ffi}/console.rb +5 -5
- data/{jruby/io/console → lib/io/console/ffi}/linux_console.rb +1 -1
- data/{jruby/io/console → lib/io/console/ffi}/native_console.rb +114 -14
- data/{jruby/io/console → lib/io/console/ffi}/stty_console.rb +14 -1
- data/{jruby/io/console → lib/io/console/ffi}/stub_console.rb +0 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a32a2bab33c5cdfeb72667a0e16580d322c3a6fa7127206ad6ec8f033b1fd503
|
4
|
+
data.tar.gz: eb107f1e5891acf99dcaf0bd6f3a664cd9f7911ace5dff034925aa7ad7e3752b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b348ea503826ebe463dde1188036c281dd5c15b433d4a2b3ada790a150022f0e71570d05ff0b59a57806ec4fdd1968986f9cc8ec3cd5a48ca3fa1499dcda1b7
|
7
|
+
data.tar.gz: 7e0facb56e8727a66eff702812adbcbae18f79d314342c1d6c29860562a3b174778c08b629d651c1331d4ba46d5a02e08bf8197c42d8caaa28055472658bd615
|
data/lib/io/console.rb
ADDED
@@ -21,11 +21,11 @@
|
|
21
21
|
|
22
22
|
require 'rbconfig'
|
23
23
|
|
24
|
-
require_relative '
|
24
|
+
require_relative 'common'
|
25
25
|
|
26
26
|
# If Windows, always use the stub version
|
27
27
|
if RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/
|
28
|
-
require_relative '
|
28
|
+
require_relative 'stub_console'
|
29
29
|
else
|
30
30
|
|
31
31
|
# If Linux or BSD, try to load the native version
|
@@ -33,7 +33,7 @@ else
|
|
33
33
|
begin
|
34
34
|
|
35
35
|
# Attempt to load the native Linux and BSD console logic
|
36
|
-
require_relative '
|
36
|
+
require_relative 'native_console'
|
37
37
|
ready = true
|
38
38
|
|
39
39
|
rescue Exception => ex
|
@@ -48,7 +48,7 @@ else
|
|
48
48
|
if !ready
|
49
49
|
begin
|
50
50
|
|
51
|
-
require_relative '
|
51
|
+
require_relative 'stty_console'
|
52
52
|
ready = true
|
53
53
|
|
54
54
|
rescue Exception
|
@@ -61,7 +61,7 @@ else
|
|
61
61
|
|
62
62
|
# If still not ready, just use stubbed version
|
63
63
|
if !ready
|
64
|
-
require_relative '
|
64
|
+
require_relative 'stub_console'
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -13,38 +13,47 @@ class IO
|
|
13
13
|
def ttymode
|
14
14
|
termios = LibC::Termios.new
|
15
15
|
if LibC.tcgetattr(self.fileno, termios) != 0
|
16
|
-
raise SystemCallError.new(
|
16
|
+
raise SystemCallError.new(path, FFI.errno)
|
17
17
|
end
|
18
18
|
|
19
19
|
if block_given?
|
20
20
|
yield tmp = termios.dup
|
21
|
-
if LibC.tcsetattr(self.fileno, LibC::
|
22
|
-
raise SystemCallError.new(
|
21
|
+
if LibC.tcsetattr(self.fileno, LibC::TCSANOW, tmp) != 0
|
22
|
+
raise SystemCallError.new(path, FFI.errno)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
termios
|
26
26
|
end
|
27
27
|
private :ttymode
|
28
28
|
|
29
|
-
def ttymode_yield(block, &setup)
|
29
|
+
def ttymode_yield(block, **opts, &setup)
|
30
30
|
begin
|
31
|
-
orig_termios = ttymode { |t| setup.call(t) }
|
31
|
+
orig_termios = ttymode { |t| setup.call(t, **opts) }
|
32
32
|
block.call(self)
|
33
33
|
ensure
|
34
|
-
if orig_termios && LibC.tcsetattr(self.fileno, LibC::
|
35
|
-
raise SystemCallError.new(
|
34
|
+
if orig_termios && LibC.tcsetattr(self.fileno, LibC::TCSANOW, orig_termios) != 0
|
35
|
+
raise SystemCallError.new(path, FFI.errno)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
private :ttymode_yield
|
40
40
|
|
41
|
-
TTY_RAW = Proc.new do |t|
|
41
|
+
TTY_RAW = Proc.new do |t, min: 1, time: nil, intr: nil|
|
42
42
|
LibC.cfmakeraw(t)
|
43
43
|
t[:c_lflag] &= ~(LibC::ECHOE|LibC::ECHOK)
|
44
|
+
if min >= 0
|
45
|
+
t[:c_cc][LibC::VMIN] = min
|
46
|
+
end
|
47
|
+
t[:c_cc][LibC::VTIME] = (time&.to_i || 0) * 10
|
48
|
+
if intr
|
49
|
+
t[:c_iflag] |= LibC::BRKINT
|
50
|
+
t[:c_lflag] |= LibC::ISIG
|
51
|
+
t[:c_oflag] |= LibC::OPOST
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
|
-
def raw(*, &block)
|
47
|
-
ttymode_yield(block, &TTY_RAW)
|
55
|
+
def raw(*, **kwargs, &block)
|
56
|
+
ttymode_yield(block, **kwargs, &TTY_RAW)
|
48
57
|
end
|
49
58
|
|
50
59
|
def raw!(*)
|
@@ -93,13 +102,25 @@ class IO
|
|
93
102
|
end
|
94
103
|
|
95
104
|
def winsize=(size)
|
105
|
+
size = size.to_ary unless size.kind_of?(Array)
|
106
|
+
sizelen = size.size
|
107
|
+
|
108
|
+
if sizelen != 2 && sizelen != 4
|
109
|
+
raise ArgumentError.new("wrong number of arguments (given #{sizelen}, expected 2 or 4)")
|
110
|
+
end
|
111
|
+
|
112
|
+
row, col, xpixel, ypixel = size
|
113
|
+
|
96
114
|
ws = LibC::Winsize.new
|
97
115
|
if LibC.ioctl(self.fileno, LibC::TIOCGWINSZ, :pointer, ws.pointer) != 0
|
98
116
|
raise SystemCallError.new("ioctl(TIOCGWINSZ)", FFI.errno)
|
99
117
|
end
|
100
118
|
|
101
|
-
ws[:ws_row] =
|
102
|
-
ws[:ws_col] =
|
119
|
+
ws[:ws_row] = row
|
120
|
+
ws[:ws_col] = col
|
121
|
+
ws[:ws_xpixel] = xpixel&.to_i || 0
|
122
|
+
ws[:ws_ypixel] = ypixel&.to_i || 0
|
123
|
+
|
103
124
|
if LibC.ioctl(self.fileno, LibC::TIOCSWINSZ, :pointer, ws.pointer) != 0
|
104
125
|
raise SystemCallError.new("ioctl(TIOCSWINSZ)", FFI.errno)
|
105
126
|
end
|
@@ -117,6 +138,80 @@ class IO
|
|
117
138
|
raise SystemCallError.new("tcflush(TCIOFLUSH)", FFI.errno) unless LibC.tcflush(self.fileno, LibC::TCIOFLUSH) == 0
|
118
139
|
end
|
119
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
|
+
|
120
215
|
# TODO: Windows version uses "conin$" and "conout$" instead of /dev/tty
|
121
216
|
def self.console(sym = nil, *args)
|
122
217
|
raise TypeError, "expected Symbol, got #{sym.class}" unless sym.nil? || sym.kind_of?(Symbol)
|
@@ -141,8 +236,13 @@ class IO
|
|
141
236
|
end
|
142
237
|
end
|
143
238
|
|
144
|
-
if !con
|
145
|
-
|
239
|
+
if !con
|
240
|
+
begin
|
241
|
+
con = File.open('/dev/tty', 'r+')
|
242
|
+
rescue
|
243
|
+
return nil
|
244
|
+
end
|
245
|
+
|
146
246
|
con.sync = true
|
147
247
|
@console = con
|
148
248
|
end
|
@@ -68,7 +68,20 @@ class IO
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def winsize=(size)
|
71
|
-
|
71
|
+
size = size.to_ary unless size.kind_of?(Array)
|
72
|
+
sizelen = size.size
|
73
|
+
|
74
|
+
if sizelen != 2 && sizelen != 4
|
75
|
+
raise ArgumentError.new("wrong number of arguments (given #{sizelen}, expected 2 or 4)")
|
76
|
+
end
|
77
|
+
|
78
|
+
row, col, xpixel, ypixel = size
|
79
|
+
|
80
|
+
if sizelen == 4
|
81
|
+
warn "stty io/console does not support pixel winsize"
|
82
|
+
end
|
83
|
+
|
84
|
+
stty("rows #{row} cols #{col}")
|
72
85
|
end
|
73
86
|
|
74
87
|
def iflush
|
File without changes
|
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.8
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: add console capabilities to IO instances.
|
14
14
|
email: nobu@ruby-lang.org
|
@@ -18,13 +18,14 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- LICENSE.txt
|
20
20
|
- README.md
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
-
|
21
|
+
- lib/io/console.rb
|
22
|
+
- lib/io/console/ffi/bsd_console.rb
|
23
|
+
- lib/io/console/ffi/common.rb
|
24
|
+
- lib/io/console/ffi/console.rb
|
25
|
+
- lib/io/console/ffi/linux_console.rb
|
26
|
+
- lib/io/console/ffi/native_console.rb
|
27
|
+
- lib/io/console/ffi/stty_console.rb
|
28
|
+
- lib/io/console/ffi/stub_console.rb
|
28
29
|
- lib/io/console/size.rb
|
29
30
|
homepage: https://github.com/ruby/io-console
|
30
31
|
licenses:
|
@@ -35,7 +36,6 @@ metadata:
|
|
35
36
|
post_install_message:
|
36
37
|
rdoc_options: []
|
37
38
|
require_paths:
|
38
|
-
- jruby
|
39
39
|
- lib
|
40
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|