tty-screen 0.6.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5df3fa646ed7439aa7a4b63e4b720c39a4cb0bc8
4
- data.tar.gz: a73ba3db03005fb018d5e0efcffeb658ed1309f4
2
+ SHA256:
3
+ metadata.gz: 4e17bafe91486f49afff31f04968d8515502eb3065f3739a796f987bd0ffed96
4
+ data.tar.gz: 80112f9584cfc84a1c76eeeff88e08cac08853714c4d6e179aa92ad753bb9175
5
5
  SHA512:
6
- metadata.gz: ef1e6aa15212200d713d5745b71c0887ebe5a5a736304e2bb17eab4db48db42e960e1700236d46d4bfb4209ad33467f7ae78868926b0f3e2c6ca11512622cbbb
7
- data.tar.gz: d71b0d07cb35f40c030477132338d8b24e443a852a20c21e52d77c2dfc57d345539f1ea00428d3455f37c083846a32fd8134be11fa59bff6ad94a50f27bdacf8
6
+ metadata.gz: c3a00a8c1cfa355c988f7999fdd2d3bd49b903cf7be4d3446cb50e8fa5bc8c17b96b9a6be7f329299ba0f6eb58a54744c2a64ccec9d9a3255498c02bbb37d876
7
+ data.tar.gz: 73a02084a05564198f93fc5bc09b1db6d2eb90d426fbc0ce0d93f965b487c240d5a5c303f651c8afacc6b688c0e0780a1bc0953c0d39fca534432d8aca8eaf44
@@ -1,5 +1,46 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.8.0] - 2020-05-28
4
+
5
+ ### Added
6
+ * Add #windows? platform check
7
+ * Add #command_exist? to see if an executable exists before running it
8
+ * Add performance tests
9
+
10
+ ### Changed
11
+ * Change #jruby? method to hoist within module
12
+ * Change #size_from_win_api to check only on windows platform and
13
+ hoist definition within module
14
+ * Change #size_from_java to hoist within module
15
+ * Change #size_from_ioctl to:
16
+ * check solaris-like system
17
+ * scan all streams to see if any attached to a terminal
18
+ * hoist definition within module
19
+ * Change #size_from_io_console to perform check on JRuby as well
20
+ * Change #size_from_readline to attempt to load readline gem
21
+ * Change #run_command to execute command directly without sub shell or temp files
22
+
23
+ ## [v0.7.1] - 2020-02-02
24
+
25
+ ### Changed
26
+ * Change gemspec to add metadata, remove test artifacts and load version directly
27
+
28
+ ## [v0.7.0] - 2019-05-19
29
+
30
+ ### Changed
31
+ * Change gemspec to load files directly without using git
32
+ * Change to relax development dependencies
33
+
34
+ ## [v0.6.5] - 2018-07-13
35
+
36
+ ### Changed
37
+ * Change to namespace version file to allow for direct vendoring
38
+
39
+ ## [v0.6.4] - 2017-12-22
40
+
41
+ ### Fixed
42
+ * Fix to suppress stderr output from run_command by Tero Marttila(@SpComb)
43
+
3
44
  ## [v0.6.3] - 2017-11-22
4
45
 
5
46
  ### Changed
@@ -90,16 +131,21 @@
90
131
  ### Fixed
91
132
  * Fix bug with screen detection from_io_console by @luxflux
92
133
 
93
- [v0.6.3]: https://github.com/peter-murach/tty-screen/compare/v0.6.2...v0.6.3
94
- [v0.6.2]: https://github.com/peter-murach/tty-screen/compare/v0.6.1...v0.6.2
95
- [v0.6.1]: https://github.com/peter-murach/tty-screen/compare/v0.6.0...v0.6.1
96
- [v0.6.0]: https://github.com/peter-murach/tty-screen/compare/v0.5.1...v0.6.0
97
- [v0.5.1]: https://github.com/peter-murach/tty-screen/compare/v0.5.0...v0.5.1
98
- [v0.5.0]: https://github.com/peter-murach/tty-screen/compare/v0.4.3...v0.5.0
99
- [v0.4.3]: https://github.com/peter-murach/tty-screen/compare/v0.4.2...v0.4.3
100
- [v0.4.2]: https://github.com/peter-murach/tty-screen/compare/v0.4.1...v0.4.2
101
- [v0.4.1]: https://github.com/peter-murach/tty-screen/compare/v0.4.0...v0.4.1
102
- [v0.4.0]: https://github.com/peter-murach/tty-screen/compare/v0.3.0...v0.4.0
103
- [v0.3.0]: https://github.com/peter-murach/tty-screen/compare/v0.2.0...v0.3.0
104
- [v0.2.0]: https://github.com/peter-murach/tty-screen/compare/v0.1.0...v0.2.0
105
- [v0.1.0]: https://github.com/peter-murach/tty-screen/compare/v0.1.0
134
+ [v0.8.0]: https://github.com/piotrmurach/tty-screen/compare/v0.7.1...v0.8.0
135
+ [v0.7.1]: https://github.com/piotrmurach/tty-screen/compare/v0.7.0...v0.7.1
136
+ [v0.7.0]: https://github.com/piotrmurach/tty-screen/compare/v0.6.5...v0.7.0
137
+ [v0.6.5]: https://github.com/piotrmurach/tty-screen/compare/v0.6.4...v0.6.5
138
+ [v0.6.4]: https://github.com/piotrmurach/tty-screen/compare/v0.6.3...v0.6.4
139
+ [v0.6.3]: https://github.com/piotrmurach/tty-screen/compare/v0.6.2...v0.6.3
140
+ [v0.6.2]: https://github.com/piotrmurach/tty-screen/compare/v0.6.1...v0.6.2
141
+ [v0.6.1]: https://github.com/piotrmurach/tty-screen/compare/v0.6.0...v0.6.1
142
+ [v0.6.0]: https://github.com/piotrmurach/tty-screen/compare/v0.5.1...v0.6.0
143
+ [v0.5.1]: https://github.com/piotrmurach/tty-screen/compare/v0.5.0...v0.5.1
144
+ [v0.5.0]: https://github.com/piotrmurach/tty-screen/compare/v0.4.3...v0.5.0
145
+ [v0.4.3]: https://github.com/piotrmurach/tty-screen/compare/v0.4.2...v0.4.3
146
+ [v0.4.2]: https://github.com/piotrmurach/tty-screen/compare/v0.4.1...v0.4.2
147
+ [v0.4.1]: https://github.com/piotrmurach/tty-screen/compare/v0.4.0...v1.4.1
148
+ [v0.4.0]: https://github.com/piotrmurach/tty-screen/compare/v0.3.0...v0.4.0
149
+ [v0.3.0]: https://github.com/piotrmurach/tty-screen/compare/v0.2.0...v0.3.0
150
+ [v0.2.0]: https://github.com/piotrmurach/tty-screen/compare/v0.1.0...v0.2.0
151
+ [v0.1.0]: https://github.com/piotrmurach/tty-screen/compare/v0.1.0
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center">
2
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="tty logo" /></a>
3
+ </div>
4
+
1
5
  # TTY::Screen [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/tty-screen.svg)][gem]
@@ -15,7 +19,7 @@
15
19
  [coverage]: https://coveralls.io/r/piotrmurach/tty-screen
16
20
  [inchpages]: http://inch-ci.org/github/piotrmurach/tty-screen
17
21
 
18
- > Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
22
+ > Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby, TruffleRuby and Rubinius interpreters.
19
23
 
20
24
  **TTY::Screen** provides independent terminal screen size detection component for [TTY](https://github.com/piotrmurach/tty) toolkit.
21
25
 
@@ -71,4 +75,4 @@ This project is intended to be a safe, welcoming space for collaboration, and co
71
75
 
72
76
  ## Copyright
73
77
 
74
- Copyright (c) 2014-2017 Piotr Murach. See LICENSE for further details.
78
+ Copyright (c) 2014 Piotr Murach. See LICENSE for further details.
@@ -1,6 +1,11 @@
1
- # fronzen_string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
- require_relative 'version'
3
+ begin
4
+ require "rbconfig"
5
+ rescue LoadError
6
+ end
7
+
8
+ require_relative "screen/version"
4
9
 
5
10
  module TTY
6
11
  # Used for detecting screen properties
@@ -13,6 +18,22 @@ module TTY
13
18
  private_class_method(name)
14
19
  end
15
20
 
21
+ case (defined?(::RbConfig) ? ::RbConfig::CONFIG["host_os"] : ::RUBY_PLATFORM)
22
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
23
+ def windows?; true end
24
+ else
25
+ def windows?; false end
26
+ end
27
+ module_function :windows?
28
+
29
+ case (defined?(::RbConfig) ? ::RbConfig::CONFIG["ruby_install_name"] : ::RUBY_ENGINE)
30
+ when /jruby/
31
+ def jruby?; true end
32
+ else
33
+ def jruby?; false end
34
+ end
35
+ module_function :jruby?
36
+
16
37
  # Default terminal size
17
38
  #
18
39
  # @api public
@@ -22,10 +43,11 @@ module TTY
22
43
  @output = $stderr
23
44
 
24
45
  class << self
46
+ # Holds the environment variables
47
+ # @api public
25
48
  attr_accessor :env
26
49
 
27
50
  # Specifies an output stream
28
- #
29
51
  # @api public
30
52
  attr_accessor :output
31
53
  end
@@ -33,20 +55,20 @@ module TTY
33
55
  # Get terminal rows and columns
34
56
  #
35
57
  # @return [Array[Integer, Integer]]
36
- # return rows & columns
58
+ # return rows and columns
37
59
  #
38
60
  # @api public
39
- def size
40
- size = size_from_java
41
- size ||= size_from_win_api
42
- size ||= size_from_ioctl
43
- size ||= size_from_io_console
44
- size ||= size_from_readline
45
- size ||= size_from_tput
46
- size ||= size_from_stty
47
- size ||= size_from_env
48
- size ||= size_from_ansicon
49
- size || DEFAULT_SIZE
61
+ def size(verbose: false)
62
+ size_from_java(verbose: verbose) ||
63
+ size_from_win_api(verbose: verbose) ||
64
+ size_from_ioctl ||
65
+ size_from_io_console(verbose: verbose) ||
66
+ size_from_readline(verbose: verbose) ||
67
+ size_from_tput ||
68
+ size_from_stty ||
69
+ size_from_env ||
70
+ size_from_ansicon ||
71
+ size_from_default
50
72
  end
51
73
  module_function :size
52
74
 
@@ -70,35 +92,49 @@ module TTY
70
92
  module_function :rows
71
93
  module_function :lines
72
94
 
73
- STDOUT_HANDLE = 0xFFFFFFF5
95
+ # Default size for the terminal
96
+ #
97
+ # @return [Array[Integer, Integer]]
98
+ #
99
+ # @api private
100
+ def size_from_default
101
+ DEFAULT_SIZE
102
+ end
103
+ module_function :size_from_default
74
104
 
75
105
  # Determine terminal size with a Windows native API
76
106
  #
77
107
  # @return [nil, Array[Integer, Integer]]
78
108
  #
79
109
  # @api private
80
- def size_from_win_api(verbose: nil)
81
- require 'fiddle'
82
-
83
- kernel32 = Fiddle::Handle.new('kernel32')
84
- get_std_handle = Fiddle::Function.new(kernel32['GetStdHandle'],
85
- [-Fiddle::TYPE_INT], Fiddle::TYPE_INT)
86
- get_console_buffer_info = Fiddle::Function.new(
87
- kernel32['GetConsoleScreenBufferInfo'],
88
- [Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
89
-
90
- format = 'SSSSSssssSS'
91
- buffer = ([0] * format.size).pack(format)
92
- stdout_handle = get_std_handle.(STDOUT_HANDLE)
93
-
94
- get_console_buffer_info.(stdout_handle, buffer)
95
- _, _, _, _, _, left, top, right, bottom, = buffer.unpack(format)
96
- size = [bottom - top + 1, right - left + 1]
97
- return size if nonzero_column?(size[1] - 1)
98
- rescue LoadError
99
- warn 'no native fiddle module found' if verbose
100
- rescue Fiddle::DLError
101
- # non windows platform or no kernel32 lib
110
+ if windows?
111
+ STDOUT_HANDLE = 0xFFFFFFF5
112
+
113
+ def size_from_win_api(verbose: false)
114
+ require "fiddle" unless defined?(Fiddle)
115
+
116
+ kernel32 = Fiddle::Handle.new("kernel32")
117
+ get_std_handle = Fiddle::Function.new(kernel32["GetStdHandle"],
118
+ [-Fiddle::TYPE_INT], Fiddle::TYPE_INT)
119
+ get_console_buffer_info = Fiddle::Function.new(
120
+ kernel32["GetConsoleScreenBufferInfo"],
121
+ [Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
122
+
123
+ format = "SSSSSssssSS"
124
+ buffer = ([0] * format.size).pack(format)
125
+ stdout_handle = get_std_handle.(STDOUT_HANDLE)
126
+
127
+ get_console_buffer_info.(stdout_handle, buffer)
128
+ _, _, _, _, _, left, top, right, bottom, = buffer.unpack(format)
129
+ size = [bottom - top + 1, right - left + 1]
130
+ return size if nonzero_column?(size[1] - 1)
131
+ rescue LoadError
132
+ warn "no native fiddle module found" if verbose
133
+ rescue Fiddle::DLError
134
+ # non windows platform or no kernel32 lib
135
+ end
136
+ else
137
+ def size_from_win_api(verbose: false); nil end
102
138
  end
103
139
  module_function :size_from_win_api
104
140
 
@@ -107,15 +143,19 @@ module TTY
107
143
  # @return [nil, Array[Integer, Integer]]
108
144
  #
109
145
  # @api private
110
- def size_from_java(verbose: nil)
111
- return unless jruby?
112
- require 'java'
113
- java_import 'jline.TerminalFactory'
114
- terminal = TerminalFactory.get
115
- size = [terminal.get_height, terminal.get_width]
116
- return size if nonzero_column?(size[1])
117
- rescue
118
- warn 'failed to import java terminal package' if verbose
146
+ if jruby?
147
+ def size_from_java(verbose: false)
148
+ require "java"
149
+
150
+ java_import "jline.TerminalFactory"
151
+ terminal = TerminalFactory.get
152
+ size = [terminal.get_height, terminal.get_width]
153
+ return size if nonzero_column?(size[1])
154
+ rescue
155
+ warn "failed to import java terminal package" if verbose
156
+ end
157
+ else
158
+ def size_from_java(verbose: false); nil end
119
159
  end
120
160
  module_function :size_from_java
121
161
 
@@ -128,62 +168,75 @@ module TTY
128
168
  # @return [nil, Array[Integer, Integer]]
129
169
  #
130
170
  # @api private
131
- def size_from_io_console(verbose: nil)
132
- return if jruby?
133
- require 'io/console'
134
-
135
- begin
136
- if @output.tty? && IO.method_defined?(:winsize)
137
- size = @output.winsize
138
- size if nonzero_column?(size[1])
139
- end
140
- rescue Errno::EOPNOTSUPP
141
- # no support for winsize on output
142
- end
171
+ def size_from_io_console(verbose: false)
172
+ require "io/console" unless IO.method_defined?(:winsize)
173
+
174
+ return unless @output.tty? && @output.respond_to?(:winsize)
175
+
176
+ size = @output.winsize
177
+ size if nonzero_column?(size[1])
178
+ rescue Errno::EOPNOTSUPP
179
+ # no support for winsize on output
143
180
  rescue LoadError
144
- warn 'no native io/console support or io-console gem' if verbose
181
+ warn "no native io/console support or io-console gem" if verbose
145
182
  end
146
183
  module_function :size_from_io_console
147
184
 
148
- TIOCGWINSZ = 0x5413
149
- TIOCGWINSZ_PPC = 0x40087468
185
+ if !jruby? && @output.respond_to?(:ioctl)
186
+ TIOCGWINSZ = 0x5413 # linux
187
+ TIOCGWINSZ_PPC = 0x40087468 # macos, freedbsd, netbsd, openbsd
188
+ TIOCGWINSZ_SOL = 0x5468 # solaris
150
189
 
151
- # Read terminal size from Unix ioctl
152
- #
153
- # @return [nil, Array[Integer, Integer]]
154
- #
155
- # @api private
156
- def size_from_ioctl
157
- return if jruby?
158
- return unless @output.respond_to?(:ioctl)
159
-
160
- format = 'SSSS'
161
- buffer = ([0] * format.size).pack(format)
162
- if ioctl?(TIOCGWINSZ, buffer) || ioctl?(TIOCGWINSZ_PPC, buffer)
163
- rows, cols, = buffer.unpack(format)[0..1]
164
- return [rows, cols] if nonzero_column?(cols)
190
+ # Read terminal size from Unix ioctl
191
+ #
192
+ # @return [nil, Array[Integer, Integer]]
193
+ #
194
+ # @api private
195
+ def size_from_ioctl
196
+ format = "SSSS"
197
+ buffer = ([0] * format.size).pack(format)
198
+
199
+ if ioctl?(TIOCGWINSZ, buffer) ||
200
+ ioctl?(TIOCGWINSZ_PPC, buffer) ||
201
+ ioctl?(TIOCGWINSZ_SOL, buffer)
202
+
203
+ rows, cols, = buffer.unpack(format)[0..1]
204
+ return [rows, cols] if nonzero_column?(cols)
205
+ end
165
206
  end
166
- end
167
- module_function :size_from_ioctl
168
207
 
169
- # Check if ioctl can be called and the device is attached to terminal
170
- #
171
- # @api private
172
- def ioctl?(control, buf)
173
- @output.ioctl(control, buf) >= 0
174
- rescue SystemCallError
175
- false
208
+ # Check if ioctl can be called and any of the streams is
209
+ # attached to a terminal.
210
+ #
211
+ # @return [Boolean]
212
+ # True if any of the streams is attached to a terminal, false otherwise.
213
+ #
214
+ # @api private
215
+ def ioctl?(control, buf)
216
+ ($stdout.ioctl(control, buf) >= 0) ||
217
+ ($stdin.ioctl(control, buf) >= 0) ||
218
+ ($stderr.ioctl(control, buf) >= 0)
219
+ rescue SystemCallError
220
+ false
221
+ end
222
+ module_function :ioctl?
223
+ else
224
+ def size_from_ioctl; nil end
176
225
  end
177
- module_function :ioctl?
226
+ module_function :size_from_ioctl
178
227
 
179
228
  # Detect screen size using Readline
180
229
  #
181
230
  # @api private
182
- def size_from_readline
183
- if defined?(Readline) && Readline.respond_to?(:get_screen_size)
184
- size = Readline.get_screen_size
185
- size if nonzero_column?(size[1])
186
- end
231
+ def size_from_readline(verbose: false)
232
+ require "readline" unless defined?(::Readline)
233
+
234
+ return unless ::Readline.respond_to?(:get_screen_size)
235
+
236
+ size = ::Readline.get_screen_size
237
+ size if nonzero_column?(size[1])
238
+ rescue LoadError
239
+ warn "no readline gem" if verbose
187
240
  rescue NotImplementedError
188
241
  end
189
242
  module_function :size_from_readline
@@ -192,11 +245,13 @@ module TTY
192
245
  #
193
246
  # @api private
194
247
  def size_from_tput
195
- return unless @output.tty?
196
- lines = run_command('tput', 'lines').to_i
197
- cols = run_command('tput', 'cols').to_i
198
- [lines, cols] if nonzero_column?(lines)
199
- rescue IOError, SystemCallError
248
+ return unless @output.tty? && command_exist?("tput")
249
+
250
+ lines = run_command("tput", "lines")
251
+ return unless lines
252
+
253
+ cols = run_command("tput", "cols")
254
+ [lines.to_i, cols.to_i] if nonzero_column?(lines)
200
255
  end
201
256
  module_function :size_from_tput
202
257
 
@@ -204,12 +259,13 @@ module TTY
204
259
  #
205
260
  # @api private
206
261
  def size_from_stty
207
- return unless @output.tty?
208
- out = run_command('stty', 'size')
262
+ return unless @output.tty? && command_exist?("stty")
263
+
264
+ out = run_command("stty", "size")
209
265
  return unless out
266
+
210
267
  size = out.split.map(&:to_i)
211
268
  size if nonzero_column?(size[1])
212
- rescue IOError, SystemCallError
213
269
  end
214
270
  module_function :size_from_stty
215
271
 
@@ -224,8 +280,9 @@ module TTY
224
280
  #
225
281
  # @api private
226
282
  def size_from_env
227
- return unless @env['COLUMNS'] =~ /^\d+$/
228
- size = [(@env['LINES'] || @env['ROWS']).to_i, @env['COLUMNS'].to_i]
283
+ return unless @env["COLUMNS"] =~ /^\d+$/
284
+
285
+ size = [(@env["LINES"] || @env["ROWS"]).to_i, @env["COLUMNS"].to_i]
229
286
  size if nonzero_column?(size[1])
230
287
  end
231
288
  module_function :size_from_env
@@ -234,24 +291,34 @@ module TTY
234
291
  #
235
292
  # @api private
236
293
  def size_from_ansicon
237
- return unless @env['ANSICON'] =~ /\((.*)x(.*)\)/
294
+ return unless @env["ANSICON"] =~ /\((.*)x(.*)\)/
295
+
238
296
  size = [$2, $1].map(&:to_i)
239
297
  size if nonzero_column?(size[1])
240
298
  end
241
299
  module_function :size_from_ansicon
242
300
 
301
+ # Check if command exists
302
+ #
303
+ # @return [Boolean]
304
+ #
305
+ # @api private
306
+ def command_exist?(command)
307
+ exts = env.fetch("PATHEXT", "").split(::File::PATH_SEPARATOR)
308
+ env.fetch("PATH", "").split(File::PATH_SEPARATOR).any? do |dir|
309
+ file = ::File.join(dir, command)
310
+ ::File.exist?(file) || exts.any? { |ext| ::File.exist?("#{file}#{ext}") }
311
+ end
312
+ end
313
+ private_module_function :command_exist?
314
+
243
315
  # Runs command silently capturing the output
244
316
  #
245
317
  # @api private
246
318
  def run_command(*args)
247
- require 'tempfile'
248
- out = Tempfile.new('tty-screen')
249
- result = system(*args, out: out.path)
250
- return if result.nil?
251
- out.rewind
252
- out.read
253
- ensure
254
- out.close if out
319
+ %x(#{args.join(" ")})
320
+ rescue IOError, SystemCallError
321
+ nil
255
322
  end
256
323
  private_module_function :run_command
257
324
 
@@ -264,10 +331,5 @@ module TTY
264
331
  column.to_i > 0
265
332
  end
266
333
  private_module_function :nonzero_column?
267
-
268
- def jruby?
269
- RbConfig::CONFIG['ruby_install_name'] == 'jruby'
270
- end
271
- private_module_function :jruby?
272
334
  end # Screen
273
335
  end # TTY
@@ -0,0 +1,7 @@
1
+ # fronzen_string_literal: true
2
+
3
+ module TTY
4
+ module Screen
5
+ VERSION = "0.8.0"
6
+ end # Screen
7
+ end # TTY
metadata CHANGED
@@ -1,81 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-screen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-22 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2.0'
19
+ version: '0'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 1.5.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
- name: rake
28
+ name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '10.0'
33
+ version: '3.0'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
- - - "~>"
38
+ - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '10.0'
40
+ version: '3.0'
47
41
  description: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
48
- platforms and supports MRI, JRuby and Rubinius interpreters.
42
+ platforms and supports MRI, JRuby, TruffleRuby and Rubinius interpreters.
49
43
  email:
50
- - ''
44
+ - piotr@piotrmurach.com
51
45
  executables: []
52
46
  extensions: []
53
- extra_rdoc_files: []
47
+ extra_rdoc_files:
48
+ - README.md
49
+ - CHANGELOG.md
50
+ - LICENSE.txt
54
51
  files:
55
- - ".gitignore"
56
- - ".rspec"
57
- - ".travis.yml"
58
52
  - CHANGELOG.md
59
- - CODE_OF_CONDUCT.md
60
- - Gemfile
61
53
  - LICENSE.txt
62
54
  - README.md
63
- - Rakefile
64
- - appveyor.yml
65
55
  - lib/tty-screen.rb
66
56
  - lib/tty/screen.rb
67
- - lib/tty/version.rb
68
- - spec/spec_helper.rb
69
- - spec/unit/height_width_spec.rb
70
- - spec/unit/size_spec.rb
71
- - tasks/console.rake
72
- - tasks/coverage.rake
73
- - tasks/spec.rake
74
- - tty-screen.gemspec
75
- homepage: https://piotrmurach.github.io/tty/
57
+ - lib/tty/screen/version.rb
58
+ homepage: https://ttytoolkit.org
76
59
  licenses:
77
60
  - MIT
78
- metadata: {}
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ bug_tracker_uri: https://github.com/piotrmurach/tty-screen/issues
64
+ changelog_uri: https://github.com/piotrmurach/tty-screen/blob/master/CHANGELOG.md
65
+ documentation_uri: https://www.rubydoc.info/gems/tty-screen
66
+ homepage_uri: https://ttytoolkit.org
67
+ source_code_uri: https://github.com/piotrmurach/tty-screen
79
68
  post_install_message:
80
69
  rdoc_options: []
81
70
  require_paths:
@@ -91,13 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
80
  - !ruby/object:Gem::Version
92
81
  version: '0'
93
82
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.5.1
83
+ rubygems_version: 3.1.2
96
84
  signing_key:
97
85
  specification_version: 4
98
86
  summary: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
99
- platforms and supports MRI, JRuby and Rubinius interpreters.
100
- test_files:
101
- - spec/spec_helper.rb
102
- - spec/unit/height_width_spec.rb
103
- - spec/unit/size_spec.rb
87
+ platforms and supports MRI, JRuby, TruffleRuby and Rubinius interpreters.
88
+ test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
@@ -1,22 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- before_install: "gem update bundler"
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.5
11
- - 2.3.1
12
- - 2.4.1
13
- - ruby-head
14
- - jruby-9000
15
- - jruby-head
16
- matrix:
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: jruby-head
20
- fast_finish: true
21
- branches:
22
- only: master
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at [email]. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rspec', '~> 3.7.0'
7
- gem 'yard', '~> 0.9.9'
8
- end
9
-
10
- group :metrics do
11
- gem 'coveralls', '~> 0.8.1'
12
- gem 'simplecov', '~> 0.10.0'
13
- gem 'yardstick', '~> 0.9.9'
14
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,21 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "200"
13
- - ruby_version: "200-x64"
14
- - ruby_version: "21"
15
- - ruby_version: "21-x64"
16
- - ruby_version: "22"
17
- - ruby_version: "22-x64"
18
- - ruby_version: "23"
19
- - ruby_version: "23-x64"
20
- - ruby_version: "24"
21
- - ruby_version: "24-x64"
@@ -1,5 +0,0 @@
1
- module TTY
2
- module Screen
3
- VERSION = "0.6.3"
4
- end # Screen
5
- end # TTY
@@ -1,43 +0,0 @@
1
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
2
- require 'simplecov'
3
- require 'coveralls'
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
-
10
- SimpleCov.start do
11
- command_name 'spec'
12
- add_filter 'spec'
13
- end
14
- end
15
-
16
- require 'tty-screen'
17
-
18
- RSpec.configure do |config|
19
- config.expect_with :rspec do |expectations|
20
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
21
- end
22
-
23
- config.mock_with :rspec do |mocks|
24
- mocks.verify_partial_doubles = true
25
- end
26
-
27
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
28
- config.disable_monkey_patching!
29
-
30
- # This setting enables warnings. It's recommended, but in some cases may
31
- # be too noisy due to issues in dependencies.
32
- config.warnings = true
33
-
34
- if config.files_to_run.one?
35
- config.default_formatter = 'doc'
36
- end
37
-
38
- config.profile_examples = 2
39
-
40
- config.order = :random
41
-
42
- Kernel.srand config.seed
43
- end
@@ -1,31 +0,0 @@
1
- RSpec.describe TTY::Screen, '#height,#width' do
2
- it "calcualtes screen width" do
3
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
4
- expect(TTY::Screen.width).to eq(280)
5
- end
6
-
7
- it "aliases width to columns" do
8
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
9
- expect(TTY::Screen.columns).to eq(280)
10
- end
11
-
12
- it "aliases width to cols" do
13
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
14
- expect(TTY::Screen.cols).to eq(280)
15
- end
16
-
17
- it "calcualtes screen height" do
18
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
19
- expect(TTY::Screen.height).to eq(51)
20
- end
21
-
22
- it "aliases width to rows" do
23
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
24
- expect(TTY::Screen.rows).to eq(51)
25
- end
26
-
27
- it "aliases width to lines" do
28
- allow(TTY::Screen).to receive(:size).and_return([51, 280])
29
- expect(TTY::Screen.lines).to eq(51)
30
- end
31
- end
@@ -1,224 +0,0 @@
1
- require 'delegate'
2
-
3
- RSpec.describe TTY::Screen, '#size' do
4
- class Output < SimpleDelegator
5
- def winsize
6
- [100, 200]
7
- end
8
-
9
- def ioctl(control, buf)
10
- buf.replace("3\x00\xD3\x00\xF2\x04\xCA\x02\x00")
11
- 0
12
- end
13
- end
14
-
15
- let(:output) { Output.new(StringIO.new('', 'w+')) }
16
-
17
- context 'size' do
18
- it "correctly falls through choices" do
19
- screen = TTY::Screen
20
- old_output = screen.output
21
- screen.output = output
22
-
23
- allow(screen).to receive(:size_from_java).and_return(nil)
24
- allow(screen).to receive(:size_from_win_api).and_return(nil)
25
- allow(screen).to receive(:size_from_ioctl).and_return(nil)
26
- allow(screen).to receive(:size_from_io_console).and_return([51, 280])
27
- allow(screen).to receive(:size_from_readline).and_return(nil)
28
-
29
- expect(screen.size).to eq([51, 280])
30
- expect(screen).to have_received(:size_from_java)
31
- expect(screen).to have_received(:size_from_win_api)
32
- expect(screen).to have_received(:size_from_ioctl)
33
- expect(screen).to_not have_received(:size_from_readline)
34
-
35
- screen.output = old_output
36
- end
37
- end
38
-
39
- context "size from java" do
40
- it "doesn't import java on non-jruby platform" do
41
- screen = TTY::Screen
42
- allow(screen).to receive(:jruby?).and_return(false)
43
- expect(screen.size_from_java).to eq(nil)
44
- end
45
-
46
- it "imports java library on jruby" do
47
- screen = TTY::Screen
48
- class << screen
49
- def java_import(*args); end
50
- end
51
- terminal = double(:terminal, get_height: 51, get_width: 211)
52
- factory = double(:factory, get: terminal)
53
- stub_const("TTY::Screen::TerminalFactory", factory)
54
-
55
- allow(screen).to receive(:jruby?).and_return(true)
56
- allow(screen).to receive(:require).with('java').and_return(true)
57
- allow(screen).to receive(:java_import)
58
-
59
- expect(screen.size_from_java).to eq([51, 211])
60
- end
61
- end
62
-
63
- context 'from io console' do
64
- it "doesn't calculate size if jruby " do
65
- screen = TTY::Screen
66
- allow(screen).to receive(:jruby?).and_return(true)
67
- expect(screen.size_from_io_console).to eq(nil)
68
- end
69
-
70
- it "calcualtes the size" do
71
- screen = TTY::Screen
72
- old_output = screen.output
73
- screen.output = output
74
-
75
- allow(screen).to receive(:jruby?).and_return(false)
76
- allow(screen).to receive(:require).with('io/console').
77
- and_return(true)
78
- allow(output).to receive(:tty?).and_return(true)
79
- allow(IO).to receive(:method_defined?).with(:winsize).and_return(true)
80
- allow(output).to receive(:winsize).and_return([100, 200])
81
-
82
- expect(screen.size_from_io_console).to eq([100, 200])
83
- expect(output).to have_received(:winsize)
84
-
85
- screen.output = old_output
86
- end
87
-
88
- it "doesn't calculate size if io/console not available" do
89
- screen = TTY::Screen
90
- allow(screen).to receive(:jruby?).and_return(false)
91
- allow(screen).to receive(:require).with('io/console').
92
- and_raise(LoadError)
93
- expect(screen.size_from_io_console).to eq(nil)
94
- end
95
-
96
- it "doesn't calculate size if it is run without a console" do
97
- screen = TTY::Screen
98
- allow(screen).to receive(:jruby?).and_return(false)
99
- allow(screen).to receive(:require).with('io/console').
100
- and_return(true)
101
- allow(screen.output).to receive(:tty?).and_return(true)
102
- allow(IO).to receive(:method_defined?).with(:winsize).and_return(false)
103
- expect(screen.size_from_io_console).to eq(nil)
104
- end
105
- end
106
-
107
- context "from ioctl" do
108
- it "reads terminal size" do
109
- screen = TTY::Screen
110
- old_output = screen.output
111
- screen.output = output
112
- allow(screen).to receive(:jruby?).and_return(false)
113
- expect(screen.size_from_ioctl).to eq([51, 211])
114
- screen.output = old_output
115
- end
116
-
117
- it "skips reading on jruby" do
118
- allow(TTY::Screen).to receive(:jruby?).and_return(true)
119
- expect(TTY::Screen.size_from_ioctl).to eq(nil)
120
- end
121
- end
122
-
123
- context 'from tput' do
124
- it "doesn't run command if outside of terminal" do
125
- allow(TTY::Screen.output).to receive(:tty?).and_return(false)
126
- expect(TTY::Screen.size_from_tput).to eq(nil)
127
- end
128
-
129
- it "runs tput commands" do
130
- screen = TTY::Screen
131
- allow(screen.output).to receive(:tty?).and_return(true)
132
- allow(screen).to receive(:run_command).with('tput', 'lines').and_return(51)
133
- allow(screen).to receive(:run_command).with('tput', 'cols').and_return(280)
134
- expect(screen.size_from_tput).to eq([51, 280])
135
- end
136
-
137
- it "doesn't return zero size" do
138
- screen = TTY::Screen
139
- allow(screen.output).to receive(:tty?).and_return(true)
140
- allow(screen).to receive(:run_command).with('tput', 'lines').and_return(0)
141
- allow(screen).to receive(:run_command).with('tput', 'cols').and_return(0)
142
- expect(screen.size_from_tput).to eq(nil)
143
- end
144
- end
145
-
146
- context 'size from stty' do
147
- it "doesn't run command if outside of terminal" do
148
- allow(TTY::Screen.output).to receive(:tty?).and_return(false)
149
- expect(TTY::Screen.size_from_stty).to eq(nil)
150
- end
151
-
152
- it "runs stty commands" do
153
- screen = TTY::Screen
154
- allow(screen.output).to receive(:tty?).and_return(true)
155
- allow(screen).to receive(:run_command).with('stty', 'size').and_return("51 280")
156
- expect(screen.size_from_stty).to eq([51, 280])
157
- end
158
-
159
- it "doesn't return zero size" do
160
- screen = TTY::Screen
161
- allow(screen.output).to receive(:tty?).and_return(true)
162
- allow(screen).to receive(:run_command).with('stty', 'size').and_return("0 0")
163
- expect(screen.size_from_stty).to eq(nil)
164
- end
165
- end
166
-
167
- context 'size from env' do
168
- it "doesn't calculate size without COLUMNS key" do
169
- screen = TTY::Screen
170
- old_env = screen.env
171
- screen.env = {'COLUMNS' => nil}
172
- expect(screen.size_from_env).to eq(nil)
173
- screen.env = old_env
174
- end
175
-
176
- it "extracts lines and columns from environment" do
177
- screen = TTY::Screen
178
- old_env = screen.env
179
- screen.env = {'COLUMNS' => '280', 'LINES' => '51'}
180
- expect(screen.size_from_env).to eq([51, 280])
181
- screen.env = old_env
182
- end
183
-
184
- it "doesn't return zero size" do
185
- screen = TTY::Screen
186
- old_env = screen.env
187
- screen.env = {'COLUMNS' => '0', 'LINES' => '0'}
188
- expect(screen.size_from_env).to eq(nil)
189
- screen.env = old_env
190
- end
191
- end
192
-
193
- context 'from ansicon' do
194
- it "doesn't calculate size without ANSICON key" do
195
- screen = TTY::Screen
196
- old_env = screen.env
197
- screen.env = {'ANSICON' => nil}
198
- expect(screen.size_from_ansicon).to eq(nil)
199
- screen.env = old_env
200
- end
201
-
202
- it "extracts lines and columns from environment" do
203
- screen = TTY::Screen
204
- old_env = screen.env
205
- screen.env = {'ANSICON' => '(280x51)'}
206
- expect(screen.size_from_ansicon).to eq([51, 280])
207
- screen.env = old_env
208
- end
209
-
210
- it "doesn't return zero size" do
211
- screen = TTY::Screen
212
- old_env = screen.env
213
- screen.env = {'ANSICON' => '(0x0)'}
214
- expect(screen.size_from_ansicon).to eq(nil)
215
- screen.env = old_env
216
- end
217
- end
218
-
219
- context 'default size' do
220
- it "suggests default terminal size" do
221
- expect(TTY::Screen::DEFAULT_SIZE).to eq([27, 80])
222
- end
223
- end
224
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require_relative '../lib/tty-screen'
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task :c => :console
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- desc 'Run all specs'
7
- RSpec::Core::RakeTask.new(:spec) do |task|
8
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
9
- end
10
-
11
- namespace :spec do
12
- desc 'Run unit specs'
13
- RSpec::Core::RakeTask.new(:unit) do |task|
14
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
15
- end
16
-
17
- desc 'Run integration specs'
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
20
- end
21
- end
22
-
23
- rescue LoadError
24
- %w[spec spec:unit spec:integration].each do |name|
25
- task name do
26
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
27
- end
28
- end
29
- end
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tty/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'tty-screen'
8
- spec.version = TTY::Screen::VERSION
9
- spec.authors = ["Piotr Murach"]
10
- spec.email = [""]
11
- spec.summary = %q{Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.}
12
- spec.description = %q{Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.}
13
- spec.homepage = "https://piotrmurach.github.io/tty/"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(spec)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.required_ruby_version = '>= 2.0.0'
22
-
23
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- end