io-console 0.9.1-java → 0.9.2-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e86817ae95f9a6fc3fa3301ea895706a3071f8e500c3c2dec9ef669dae510609
4
- data.tar.gz: 433bb663068ef08dbc2a076c0d037d94872f2906652bd198ee950fff5c3a1bc7
3
+ metadata.gz: 1fd5a5305181bf526a7053c3303f099b0fa0e47d8791fa35c310e5af5ed5d5b9
4
+ data.tar.gz: 9db378bc55068b6c1ca6e79b57be5955013d577307d8a5faf50f4869ac3e5108
5
5
  SHA512:
6
- metadata.gz: ec7274caecc4e434b7a1e7afe30251d1b07f677c54d3865f3b341c008f96ca6a7d95faa7c87faacbbf65734ee7a0e23bbdfb469088349a03c1cacc5f82be3bee
7
- data.tar.gz: a9b72f79b80a65809217ed7cdab1edeb01daa53ffe9647d42900960569f4db3e83bb869c80f8da8ee9b2c76d23a66b08cc5d879a373a9ac9d9f6bdd05c0c8a66
6
+ metadata.gz: 24b6dac4157c567a4caa5d6228375f38aa091de553ab8971dfe31c8a0c5af25c57c6b3c0235b6ba41ffc95711d8dfe85224c6486da85a50ceabddc57048a46fc
7
+ data.tar.gz: 577c04bb5a8ff5808418a74bd7835c7a795c8998b0fecbe71954ffe166f47fdc9f66c3fbe018b37232b91cb567d207a65679d1a084e2131528a429fb2fae749c
@@ -1,8 +1,72 @@
1
+ require 'ffi'
2
+
3
+ case RbConfig::CONFIG['host_os']
4
+ when /darwin/i
5
+ tested_platforms = /i386|x86_64|aarch64/
6
+ unless tested_platforms.match?(FFI::Platform::ARCH)
7
+ raise LoadError, "native console on MacOS only supported on #{tested_platforms.source.gsub('|', ', ')}"
8
+ end
9
+ when /linux/i
10
+ tested_platforms = /i386|x86_64|powerpc64|aarch64|s390x/
11
+ unless tested_platforms.match?(FFI::Platform::ARCH)
12
+ warn "native console only tested on #{tested_platforms.source.gsub('|', ', ')}"
13
+ end
14
+ end
15
+
16
+ module IO::Console::LibC
17
+ include IO::Console::Constants
18
+ extend FFI::Library
19
+ ffi_lib FFI::Library::LIBC
20
+
21
+ typedef TCFLAG_TYPE, :tcflag_t
22
+ typedef SPEED_TYPE, :speed_t
23
+
24
+ class Termios < FFI::Struct
25
+ constants = IO::Console::Constants
26
+ fields = [
27
+ :c_iflag, :tcflag_t,
28
+ :c_oflag, :tcflag_t,
29
+ :c_cflag, :tcflag_t,
30
+ :c_lflag, :tcflag_t,
31
+ ]
32
+ fields.concat([:c_line, :uchar]) if constants::TERMIOS_HAS_LINE
33
+ fields.concat([
34
+ :c_cc, [:uchar, constants::NCCS],
35
+ :c_ispeed, :speed_t,
36
+ :c_ospeed, :speed_t,
37
+ ])
38
+ layout(*fields)
39
+ end
40
+
41
+ class Winsize < FFI::Struct
42
+ layout \
43
+ :ws_row, :ushort,
44
+ :ws_col, :ushort,
45
+ :ws_xpixel, :ushort,
46
+ :ws_ypixel, :ushort
47
+ end
48
+
49
+ attach_function :tcsetattr, [:int, :int, :pointer], :int
50
+ attach_function :tcgetattr, [:int, :pointer], :int
51
+ attach_function :cfgetispeed, [:pointer], :speed_t
52
+ attach_function :cfgetospeed, [:pointer], :speed_t
53
+ attach_function :cfsetispeed, [:pointer, :speed_t], :int
54
+ attach_function :cfsetospeed, [:pointer, :speed_t], :int
55
+ attach_function :cfmakeraw, [:pointer], :void
56
+ attach_function :tcflush, [:int, :int], :int
57
+ attach_function :ioctl, [:int, :ulong, :varargs], :int
58
+ end
59
+
1
60
  # Common logic that uses native calls for console
2
61
  module IO::Console
3
62
  def ttymode
4
63
  termios = LibC::Termios.new
5
- if LibC.tcgetattr(self.fileno, termios) != 0
64
+ result = if LibC.const_defined?(:TIOCGETA)
65
+ LibC.ioctl(fileno, LibC::TIOCGETA, :pointer, termios.pointer)
66
+ else
67
+ LibC.tcgetattr(fileno, termios.pointer)
68
+ end
69
+ if result != 0
6
70
  raise SystemCallError.new(respond_to?(:path) ? path : "tcgetattr", FFI.errno)
7
71
  end
8
72
 
@@ -15,7 +79,12 @@ module IO::Console
15
79
  private :ttymode
16
80
 
17
81
  def ttymode_set(termios)
18
- if LibC.tcsetattr(self.fileno, LibC::TCSANOW, termios) != 0
82
+ result = if LibC.const_defined?(:TIOCSETA)
83
+ LibC.ioctl(fileno, LibC::TIOCSETA, :pointer, termios.pointer)
84
+ else
85
+ LibC.tcsetattr(fileno, LibC::TCSANOW, termios.pointer)
86
+ end
87
+ if result != 0
19
88
  raise SystemCallError.new(respond_to?(:path) ? path : "tcsetattr(TCSANOW)", FFI.errno)
20
89
  end
21
90
  end
@@ -34,7 +103,7 @@ module IO::Console
34
103
  private :ttymode_yield
35
104
 
36
105
  TTY_RAW = Proc.new do |t, min: 1, time: nil, intr: nil|
37
- LibC.cfmakeraw(t)
106
+ LibC.cfmakeraw(t.pointer)
38
107
  t[:c_lflag] &= ~(LibC::ECHOE|LibC::ECHOK)
39
108
  if min >= 0
40
109
  t[:c_cc][LibC::VMIN] = min
@@ -1,13 +1,6 @@
1
1
  require 'ffi'
2
2
 
3
3
  module IO::Console::Windows
4
- STD_INPUT_HANDLE = -10
5
- STD_OUTPUT_HANDLE = -11
6
- WAIT_OBJECT_0 = 0
7
- WAIT_TIMEOUT = 258
8
- ENABLE_WRAP_AT_EOL_OUTPUT = 2
9
- ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
10
-
11
4
  module Native
12
5
  extend FFI::Library
13
6
  ffi_convention :stdcall
@@ -3,13 +3,44 @@ module IO::Console
3
3
  STTY = %w[/usr/bin/stty /bin/stty].find {|path| File.executable?(path)}
4
4
  end
5
5
 
6
- unless IO::Console::STTY &&
7
- system(IO::Console::STTY, out: File::NULL, err: %i[child out])
8
- raise "stty command returned nonzero exit status"
9
- end
6
+ raise LoadError, "stty command not found" unless IO::Console::STTY
10
7
 
11
8
  warn "io/console on JRuby shells out to stty for most operations" if $VERBOSE
12
9
 
10
+ class IO::Console::Mode
11
+ def initialize(saved)
12
+ @saved = saved
13
+ @args = []
14
+ end
15
+
16
+ def initialize_copy(mode)
17
+ super
18
+ @saved = mode.__send__(:saved).dup
19
+ @args = mode.__send__(:args).dup
20
+ end
21
+
22
+ def echo=(echo)
23
+ @args << (echo ? 'echo' : '-echo')
24
+ echo
25
+ end
26
+
27
+ def raw(min: 1, time: nil, intr: nil)
28
+ dup.raw!(min:, time:, intr:)
29
+ end
30
+
31
+ def raw!(min: 1, time: nil, intr: nil)
32
+ @args << 'raw'
33
+ @args.push('min', min.to_s) if min >= 0
34
+ @args.push('time', ((time || 0) * 10).to_i.to_s)
35
+ @args.concat(%w[brkint isig opost]) if intr
36
+ self
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :saved, :args
42
+ end
43
+
13
44
  # Non-Windows assumes stty command is available
14
45
  class IO
15
46
  private def _io_console_stty(*args)
@@ -34,11 +65,11 @@ class IO
34
65
  end
35
66
 
36
67
  def raw(*, min: 1, time: nil, intr: nil)
37
- saved = _io_console_stty('-g')
38
- _io_console_stty('raw')
68
+ saved = console_mode
69
+ self.console_mode = saved.raw(min:, time:, intr:)
39
70
  yield self
40
71
  ensure
41
- _io_console_stty(saved) if saved
72
+ self.console_mode = saved if saved
42
73
  end
43
74
 
44
75
  def raw!(*)
@@ -73,6 +104,15 @@ class IO
73
104
  _io_console_stty(saved) if saved
74
105
  end
75
106
 
107
+ def console_mode
108
+ Console::Mode.new(_io_console_stty('-g').chomp)
109
+ end
110
+
111
+ def console_mode=(mode)
112
+ _io_console_stty(mode.__send__(:saved), *mode.__send__(:args))
113
+ mode
114
+ end
115
+
76
116
  # Not all systems return same format of stty -a output
77
117
  IEEE_STD_1003_2 = '(?<rows>\d+) rows; (?<columns>\d+) columns'
78
118
  UBUNTU = 'rows (?<rows>\d+); columns (?<columns>\d+)'
@@ -96,7 +136,7 @@ class IO
96
136
 
97
137
  row, col, _, _ = size
98
138
 
99
- _io_console_stty("rows #{row} cols #{col}")
139
+ _io_console_stty('rows', row.to_s, 'cols', col.to_s)
100
140
  end
101
141
 
102
142
  def iflush
@@ -1,22 +1,14 @@
1
- require 'ffi'
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
-
9
- module IO::Console::LibC
10
- extend FFI::Library
11
- ffi_lib FFI::Library::LIBC
12
-
13
- if RbConfig::CONFIG['host_os'].downcase =~ /darwin/
14
- typedef :ulong, :tcflag_t
15
- typedef :ulong, :speed_t
1
+ module IO::Console::Constants
2
+ if /darwin/i.match?(RbConfig::CONFIG['host_os'])
3
+ TCFLAG_TYPE = :ulong
4
+ SPEED_TYPE = :ulong
5
+ TIOCGETA = 0x40487413
6
+ TIOCSETA = 0x80487414
16
7
  else
17
- typedef :uint, :tcflag_t
18
- typedef :uint, :speed_t
8
+ TCFLAG_TYPE = :uint
9
+ SPEED_TYPE = :uint
19
10
  end
11
+ TERMIOS_HAS_LINE = false
20
12
 
21
13
  # Special Control Characters
22
14
  VEOF = 0 # ICANON
@@ -124,51 +116,6 @@ module IO::Console::LibC
124
116
  IOCPARM_MASK = 0x1fff
125
117
  IOC_OUT = 0x40000000
126
118
  IOC_IN = 0x80000000
127
-
128
- def self._IOC(inout,group,num,len)
129
- inout | ((len & IOCPARM_MASK) << 16) | ((group.ord << 8) | num)
130
- end
131
-
132
- def self._IOR(g,n,t)
133
- self._IOC(IOC_OUT, g, n, find_type(t).size)
134
- end
135
-
136
- def self._IOW(g,n,t)
137
- self._IOC(IOC_IN, g, n, find_type(t).size)
138
- end
139
-
140
-
141
- class Termios < FFI::Struct
142
- layout \
143
- :c_iflag, :tcflag_t,
144
- :c_oflag, :tcflag_t,
145
- :c_cflag, :tcflag_t,
146
- :c_lflag, :tcflag_t,
147
- :c_cc, [ :uchar, NCCS ],
148
- :c_ispeed, :speed_t,
149
- :c_ospeed, :speed_t
150
- end
151
-
152
- class Winsize < FFI::Struct
153
- layout \
154
- :ws_row, :ushort,
155
- :ws_col, :ushort,
156
- :ws_xpixel, :ushort,
157
- :ws_ypixel, :ushort
158
- end
159
-
160
- TIOCGWINSZ = _IOR('t', 104, Winsize) # get window size
161
- TIOCSWINSZ = _IOW('t', 103, Winsize) # set window size
162
-
163
- attach_function :tcsetattr, [ :int, :int, Termios ], :int
164
- attach_function :tcgetattr, [ :int, Termios ], :int
165
- attach_function :cfgetispeed, [ Termios ], :speed_t
166
- attach_function :cfgetospeed, [ Termios ], :speed_t
167
- attach_function :cfsetispeed, [ Termios, :speed_t ], :int
168
- attach_function :cfsetospeed, [ Termios, :speed_t ], :int
169
- attach_function :cfmakeraw, [ Termios ], :int
170
- attach_function :tcflush, [ :int, :int ], :int
171
- attach_function :ioctl, [ :int, :ulong, :varargs ], :int
119
+ TIOCGWINSZ = 0x40087468
120
+ TIOCSWINSZ = 0x80087467
172
121
  end
173
-
174
- require_relative 'native_console'
@@ -1,17 +1,7 @@
1
- require 'ffi'
2
-
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(', ')}"
7
- end
8
-
9
- module IO::Console::LibC
10
- extend FFI::Library
11
- ffi_lib FFI::Library::LIBC
12
-
13
- typedef :uint, :tcflag_t
14
- typedef :uint, :speed_t
1
+ module IO::Console::Constants
2
+ TCFLAG_TYPE = :uint
3
+ SPEED_TYPE = :uint
4
+ TERMIOS_HAS_LINE = true
15
5
 
16
6
  VINTR = 0
17
7
  VQUIT = 1
@@ -168,39 +158,6 @@ module IO::Console::LibC
168
158
  TCSADRAIN = 1
169
159
  TCSAFLUSH = 2
170
160
  NCCS = 32
171
- class Termios < FFI::Struct
172
- layout \
173
- :c_iflag, :tcflag_t,
174
- :c_oflag, :tcflag_t,
175
- :c_cflag, :tcflag_t,
176
- :c_lflag, :tcflag_t,
177
- :c_line, :uchar,
178
- :c_cc, [ :uchar, NCCS ],
179
- :c_ispeed, :speed_t,
180
- :c_ospeed, :speed_t
181
- end
182
-
183
- class Winsize < FFI::Struct
184
- layout \
185
- :ws_row, :ushort,
186
- :ws_col, :ushort,
187
- :ws_xpixel, :ushort,
188
- :ws_ypixel, :ushort
189
- end
190
-
191
-
192
161
  TIOCGWINSZ = 0x5413
193
162
  TIOCSWINSZ = 0x5414
194
-
195
- attach_function :tcsetattr, [ :int, :int, Termios ], :int
196
- attach_function :tcgetattr, [ :int, Termios ], :int
197
- attach_function :cfgetispeed, [ Termios ], :speed_t
198
- attach_function :cfgetospeed, [ Termios ], :speed_t
199
- attach_function :cfsetispeed, [ Termios, :speed_t ], :int
200
- attach_function :cfsetospeed, [ Termios, :speed_t ], :int
201
- attach_function :cfmakeraw, [ Termios ], :int
202
- attach_function :tcflush, [ :int, :int ], :int
203
- attach_function :ioctl, [ :int, :ulong, :varargs ], :int
204
163
  end
205
-
206
- require_relative 'native_console'
@@ -1,4 +1,11 @@
1
1
  module IO::Console::Windows
2
+ STD_INPUT_HANDLE = -10
3
+ STD_OUTPUT_HANDLE = -11
4
+ WAIT_OBJECT_0 = 0
5
+ WAIT_TIMEOUT = 258
6
+ ENABLE_WRAP_AT_EOL_OUTPUT = 2
7
+ ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
8
+
2
9
  VK_TAB = 0x09
3
10
  VK_RETURN = 0x0d
4
11
  VK_SHIFT = 0x10
@@ -1,5 +1,5 @@
1
1
  class IO
2
2
  module Console
3
- VERSION = "0.9.1"
3
+ VERSION = "0.9.2"
4
4
  end
5
5
  end
@@ -36,28 +36,29 @@ class IO
36
36
  deprecate_constant :ConsoleMode
37
37
  end
38
38
 
39
- libs = []
39
+ backends = []
40
40
  # If Linux or BSD, try to load the native version
41
- case RbConfig::CONFIG['host_os'].downcase
42
- when /darwin|openbsd|freebsd|netbsd/
43
- libs << 'bsd' << 'stty'
44
- when /linux/
45
- libs << 'linux' << 'stty'
41
+ case RbConfig::CONFIG['host_os']
42
+ when /darwin|openbsd|freebsd|netbsd/i
43
+ backends << %w[ffi/termios bsd] << %w[stty]
44
+ when /linux/i
45
+ backends << %w[ffi/termios linux] << %w[stty]
46
46
  when /mswin|win32|ming/i
47
- require_relative 'console/windows_constants'
48
- require_relative 'console/windows_console'
47
+ require_relative 'console/constants/windows'
48
+ require_relative 'console/backend/ffi/windows'
49
49
  return
50
50
  else
51
- libs << 'stty'
51
+ backends << %w[stty]
52
52
  end
53
53
 
54
- return if libs.any? do |lib|
55
- require_relative "console/#{lib}_console"
54
+ return if backends.any? do |backend, constants|
55
+ require_relative "console/constants/#{constants}" if constants
56
+ require_relative "console/backend/#{backend}"
56
57
  rescue Exception => ex
57
- warn "failed to load #{lib} console support: #{ex}" if $VERBOSE
58
+ warn "failed to load #{backend.split('/', 2).first} console support: #{ex}" if $VERBOSE
58
59
  else
59
60
  true
60
61
  end
61
62
 
62
63
  # If still not ready, just use stubbed version
63
- require_relative "console/stub_console"
64
+ require_relative 'console/backend/stub'
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.1
4
+ version: 0.9.2
5
5
  platform: java
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-08-08 00:00:00.000000000 Z
10
+ date: 2026-08-10 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: add console capabilities to IO instances.
13
13
  email: nobu@ruby-lang.org
@@ -19,16 +19,16 @@ files:
19
19
  - BSDL
20
20
  - COPYING
21
21
  - README.md
22
- - lib/ffi/io/console.rb
23
- - lib/ffi/io/console/bsd_console.rb
24
- - lib/ffi/io/console/common.rb
25
- - lib/ffi/io/console/linux_console.rb
26
- - lib/ffi/io/console/native_console.rb
27
- - lib/ffi/io/console/stty_console.rb
28
- - lib/ffi/io/console/stub_console.rb
29
- - lib/ffi/io/console/version.rb
30
- - lib/ffi/io/console/windows_console.rb
31
- - lib/ffi/io/console/windows_constants.rb
22
+ - jruby/lib/io/console.rb
23
+ - jruby/lib/io/console/backend/ffi/termios.rb
24
+ - jruby/lib/io/console/backend/ffi/windows.rb
25
+ - jruby/lib/io/console/backend/stty.rb
26
+ - jruby/lib/io/console/backend/stub.rb
27
+ - jruby/lib/io/console/common.rb
28
+ - jruby/lib/io/console/constants/bsd.rb
29
+ - jruby/lib/io/console/constants/linux.rb
30
+ - jruby/lib/io/console/constants/windows.rb
31
+ - jruby/lib/io/console/version.rb
32
32
  - lib/io/console/size.rb
33
33
  homepage: https://github.com/ruby/io-console
34
34
  licenses:
@@ -39,7 +39,7 @@ metadata:
39
39
  changelog_uri: https://github.com/ruby/io-console/releases
40
40
  rdoc_options: []
41
41
  require_paths:
42
- - lib/ffi
42
+ - jruby/lib
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
File without changes