tty-screen 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +11 -2
- data/lib/tty/screen.rb +15 -128
- data/lib/tty/screen/color.rb +77 -0
- data/lib/tty/screen/size.rb +147 -0
- data/lib/tty/screen/version.rb +1 -1
- data/spec/unit/color_spec.rb +51 -0
- data/spec/unit/new_spec.rb +55 -0
- data/spec/unit/size_spec.rb +5 -15
- data/tty-screen.gemspec +2 -2
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0796330d2cffb4c8486e6648f98cbb37a56b0d89
|
4
|
+
data.tar.gz: d1f15d6630f40dcda049190a07c431d6b750f161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca4c5c2e18579c49788196cf445b63bcb1b3ba4269e7e551f931181ff03e3a90a55f8c3a6ac959d4bb90914b69d61c878b309a4eabe51d30af3d6268d3c59d7
|
7
|
+
data.tar.gz: ca7fd84dd32d005f9bdadb9d8fc69a7d0cacb42b57e4155aa3f6292ff89c582ac0de9bf0e029813000613823d1c2ed0df4a0044c29689495285e736c37336ba9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,9 +11,9 @@
|
|
11
11
|
[coverage]: https://coveralls.io/r/peter-murach/tty-screen
|
12
12
|
[inchpages]: http://inch-ci.org/github/peter-murach/tty-screen
|
13
13
|
|
14
|
-
> Terminal screen size detection which works both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
14
|
+
> Terminal screen size and color detection which works both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
15
15
|
|
16
|
-
**TTY::Screen** provides independent screen size detection component for [TTY](https://github.com/peter-murach/tty) toolkit.
|
16
|
+
**TTY::Screen** provides independent screen size and color detection component for [TTY](https://github.com/peter-murach/tty) toolkit.
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -43,12 +43,21 @@ screen.width # => 280
|
|
43
43
|
screen.height # => 51
|
44
44
|
```
|
45
45
|
|
46
|
+
Using the `color?` method, you can check whether terminal has color capabilities like so
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
screen = TTY::Screen.new
|
50
|
+
screen.color? # => true
|
51
|
+
```
|
52
|
+
|
46
53
|
You can also use above methods as class instance methods:
|
47
54
|
|
48
55
|
```ruby
|
49
56
|
TTY::Screen.size # => [51, 280]
|
50
57
|
TTY::Screen.width # => 280
|
51
58
|
TTY::Screen.height # => 51
|
59
|
+
|
60
|
+
TTY::Screen.color? # => true
|
52
61
|
```
|
53
62
|
|
54
63
|
## Contributing
|
data/lib/tty/screen.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require 'tty/screen/color'
|
4
|
+
require 'tty/screen/size'
|
3
5
|
require 'tty/screen/version'
|
4
6
|
|
5
7
|
module TTY
|
@@ -16,6 +18,8 @@ module TTY
|
|
16
18
|
# @api public
|
17
19
|
def initialize(options = {})
|
18
20
|
@output = options.fetch(:output) { $stderr }
|
21
|
+
@color = Color.new(output: @output)
|
22
|
+
@size = Size.new(output: @output)
|
19
23
|
end
|
20
24
|
|
21
25
|
# @api public
|
@@ -33,14 +37,12 @@ module TTY
|
|
33
37
|
size[0]
|
34
38
|
end
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
ENV['COLUMNS'].to_i.nonzero? || 80
|
43
|
-
]
|
40
|
+
def self.color?
|
41
|
+
new.color?
|
42
|
+
end
|
43
|
+
|
44
|
+
def size
|
45
|
+
@size.size
|
44
46
|
end
|
45
47
|
|
46
48
|
# Terminal lines count
|
@@ -63,129 +65,14 @@ module TTY
|
|
63
65
|
end
|
64
66
|
alias_method :columns, :width
|
65
67
|
|
66
|
-
#
|
68
|
+
# Check if terminal has color support
|
67
69
|
#
|
68
|
-
# @return [
|
69
|
-
#
|
70
|
+
# @return [Boolean]
|
71
|
+
# true if can display color, false otherwise
|
70
72
|
#
|
71
73
|
# @api public
|
72
|
-
def
|
73
|
-
@
|
74
|
-
size = from_io_console
|
75
|
-
size ||= from_readline
|
76
|
-
size ||= from_tput
|
77
|
-
size ||= from_stty
|
78
|
-
size ||= from_env
|
79
|
-
size ||= from_ansicon
|
80
|
-
size || default_size
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Detect screen size by loading io/console lib
|
85
|
-
#
|
86
|
-
# @return [Array[Integer, Integer]]
|
87
|
-
#
|
88
|
-
# @api private
|
89
|
-
def from_io_console
|
90
|
-
return false if jruby?
|
91
|
-
try_io_console { |size|
|
92
|
-
size if nonzero_column?(size[1])
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
# Attempts to load native console extension
|
97
|
-
#
|
98
|
-
# @return [Boolean, Array]
|
99
|
-
#
|
100
|
-
# @api private
|
101
|
-
def try_io_console
|
102
|
-
begin
|
103
|
-
require 'io/console'
|
104
|
-
|
105
|
-
begin
|
106
|
-
if output.tty? && IO.method_defined?(:winsize)
|
107
|
-
yield output.winsize
|
108
|
-
else
|
109
|
-
false
|
110
|
-
end
|
111
|
-
rescue Errno::EOPNOTSUPP
|
112
|
-
false
|
113
|
-
end
|
114
|
-
rescue LoadError
|
115
|
-
warn 'no native io/console support' if $VERBOSE
|
116
|
-
false
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Detect screen size using Readline
|
121
|
-
#
|
122
|
-
# @api private
|
123
|
-
def from_readline
|
124
|
-
return unless defined?(Readline)
|
125
|
-
size = Readline.get_screen_size
|
126
|
-
size if nonzero_column?(size[1])
|
127
|
-
rescue NotImplementedError
|
128
|
-
end
|
129
|
-
|
130
|
-
# Detect terminal size from tput utility
|
131
|
-
#
|
132
|
-
# @api private
|
133
|
-
def from_tput
|
134
|
-
return unless output.tty?
|
135
|
-
lines = run_command('tput', 'lines').to_i
|
136
|
-
cols = run_command('tput', 'cols').to_i
|
137
|
-
[lines, cols] if nonzero_column?(lines)
|
138
|
-
rescue Errno::ENOENT
|
139
|
-
end
|
140
|
-
|
141
|
-
# Detect terminal size from stty utility
|
142
|
-
#
|
143
|
-
# @api private
|
144
|
-
def from_stty
|
145
|
-
return unless output.tty?
|
146
|
-
size = run_command('stty', 'size').split.map(&:to_i)
|
147
|
-
size if nonzero_column?(size[1])
|
148
|
-
rescue Errno::ENOENT
|
149
|
-
end
|
150
|
-
|
151
|
-
# Detect terminal size from environment
|
152
|
-
#
|
153
|
-
# @api private
|
154
|
-
def from_env
|
155
|
-
return unless ENV['COLUMNS'] =~ /^\d+$/
|
156
|
-
size = [(ENV['LINES'] || ENV['ROWS']).to_i, ENV['COLUMNS'].to_i]
|
157
|
-
size if nonzero_column?(size[1])
|
158
|
-
end
|
159
|
-
|
160
|
-
# Detect terminal size on windows
|
161
|
-
#
|
162
|
-
# @api private
|
163
|
-
def from_ansicon
|
164
|
-
return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
|
165
|
-
size = [$2, $1].map(&:to_i)
|
166
|
-
size if nonzero_column?(size[1])
|
167
|
-
end
|
168
|
-
|
169
|
-
private
|
170
|
-
|
171
|
-
# Specifies an output stream object
|
172
|
-
#
|
173
|
-
# @api public
|
174
|
-
attr_reader :output
|
175
|
-
|
176
|
-
# Runs command in subprocess
|
177
|
-
#
|
178
|
-
# @api private
|
179
|
-
def run_command(command, *args)
|
180
|
-
`#{command} #{args.join(' ')} 2>/dev/null`
|
181
|
-
end
|
182
|
-
|
183
|
-
def nonzero_column?(column)
|
184
|
-
column.to_i > 0
|
185
|
-
end
|
186
|
-
|
187
|
-
def jruby?
|
188
|
-
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
74
|
+
def color?
|
75
|
+
@color.supports?
|
189
76
|
end
|
190
77
|
end # Screen
|
191
78
|
end # TTY
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
class Screen
|
5
|
+
class Color
|
6
|
+
# Initialize color support
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
def initialize(options = {})
|
10
|
+
@output = options.fetch(:output) { $stderr }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Detect if terminal supports color
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
16
|
+
# true when terminal supports color, false otherwise
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def supports?
|
20
|
+
return false unless tty?
|
21
|
+
|
22
|
+
from_curses || from_tput || from_term || from_env
|
23
|
+
end
|
24
|
+
|
25
|
+
# Attempt to load curses to check color support
|
26
|
+
#
|
27
|
+
# @return [Boolean]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
def from_curses(curses_class = nil)
|
31
|
+
require 'curses'
|
32
|
+
|
33
|
+
begin
|
34
|
+
curses_class ||= Curses
|
35
|
+
curses_class.init_screen
|
36
|
+
curses_class.has_colors?
|
37
|
+
ensure
|
38
|
+
curses_class.close_screen
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
warn 'no native curses support' if $VERBOSE
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
# Shell out to tput to check color support
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
def from_tput
|
49
|
+
%x(tput colors 2>/dev/null).to_i > 2
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
# Inspect environment $TERM variable for color support
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
def from_term
|
58
|
+
if ENV['TERM'] == 'dumb'
|
59
|
+
false
|
60
|
+
elsif ENV['TERM'] =~ /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i
|
61
|
+
true
|
62
|
+
else false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def from_env
|
67
|
+
ENV.include?('COLORTERM')
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_reader :output
|
71
|
+
|
72
|
+
def tty?
|
73
|
+
output.tty?
|
74
|
+
end
|
75
|
+
end # Color
|
76
|
+
end # Screen
|
77
|
+
end # TTY
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
class Screen
|
5
|
+
class Size
|
6
|
+
# Initialize terminal size detection
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
def initialize(options = {})
|
10
|
+
@output = options.fetch(:output) { $stderr }
|
11
|
+
end
|
12
|
+
|
13
|
+
# Get terminal rows and columns
|
14
|
+
#
|
15
|
+
# @return [Array[Integer, Integer]]
|
16
|
+
# return rows & columns
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def size
|
20
|
+
size = from_io_console
|
21
|
+
size ||= from_readline
|
22
|
+
size ||= from_tput
|
23
|
+
size ||= from_stty
|
24
|
+
size ||= from_env
|
25
|
+
size ||= from_ansicon
|
26
|
+
size || default_size
|
27
|
+
end
|
28
|
+
|
29
|
+
# Detect screen size by loading io/console lib
|
30
|
+
#
|
31
|
+
# @return [Array[Integer, Integer]]
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
def from_io_console
|
35
|
+
return false if jruby?
|
36
|
+
try_io_console { |size|
|
37
|
+
size if nonzero_column?(size[1])
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Attempts to load native console extension
|
42
|
+
#
|
43
|
+
# @return [Boolean, Array]
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
def try_io_console
|
47
|
+
begin
|
48
|
+
require 'io/console'
|
49
|
+
|
50
|
+
begin
|
51
|
+
if output.tty? && IO.method_defined?(:winsize)
|
52
|
+
yield output.winsize
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
rescue Errno::EOPNOTSUPP
|
57
|
+
false
|
58
|
+
end
|
59
|
+
rescue LoadError
|
60
|
+
warn 'no native io/console support' if $VERBOSE
|
61
|
+
false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Detect screen size using Readline
|
66
|
+
#
|
67
|
+
# @api private
|
68
|
+
def from_readline
|
69
|
+
return unless defined?(Readline)
|
70
|
+
size = Readline.get_screen_size
|
71
|
+
size if nonzero_column?(size[1])
|
72
|
+
rescue NotImplementedError
|
73
|
+
end
|
74
|
+
|
75
|
+
# Detect terminal size from tput utility
|
76
|
+
#
|
77
|
+
# @api private
|
78
|
+
def from_tput
|
79
|
+
return unless output.tty?
|
80
|
+
lines = run_command('tput', 'lines').to_i
|
81
|
+
cols = run_command('tput', 'cols').to_i
|
82
|
+
[lines, cols] if nonzero_column?(lines)
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
end
|
85
|
+
|
86
|
+
# Detect terminal size from stty utility
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
def from_stty
|
90
|
+
return unless output.tty?
|
91
|
+
size = run_command('stty', 'size').split.map(&:to_i)
|
92
|
+
size if nonzero_column?(size[1])
|
93
|
+
rescue Errno::ENOENT
|
94
|
+
end
|
95
|
+
|
96
|
+
# Detect terminal size from environment
|
97
|
+
#
|
98
|
+
# @api private
|
99
|
+
def from_env
|
100
|
+
return unless ENV['COLUMNS'] =~ /^\d+$/
|
101
|
+
size = [(ENV['LINES'] || ENV['ROWS']).to_i, ENV['COLUMNS'].to_i]
|
102
|
+
size if nonzero_column?(size[1])
|
103
|
+
end
|
104
|
+
|
105
|
+
# Detect terminal size on windows
|
106
|
+
#
|
107
|
+
# @api private
|
108
|
+
def from_ansicon
|
109
|
+
return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
|
110
|
+
size = [$2, $1].map(&:to_i)
|
111
|
+
size if nonzero_column?(size[1])
|
112
|
+
end
|
113
|
+
|
114
|
+
# Default terminal size
|
115
|
+
#
|
116
|
+
# @api public
|
117
|
+
def default_size
|
118
|
+
[
|
119
|
+
ENV['LINES'].to_i.nonzero? || 27,
|
120
|
+
ENV['COLUMNS'].to_i.nonzero? || 80
|
121
|
+
]
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
# Specifies an output stream object
|
127
|
+
#
|
128
|
+
# @api public
|
129
|
+
attr_reader :output
|
130
|
+
|
131
|
+
# Runs command in subprocess
|
132
|
+
#
|
133
|
+
# @api private
|
134
|
+
def run_command(command, *args)
|
135
|
+
`#{command} #{args.join(' ')} 2>/dev/null`
|
136
|
+
end
|
137
|
+
|
138
|
+
def nonzero_column?(column)
|
139
|
+
column.to_i > 0
|
140
|
+
end
|
141
|
+
|
142
|
+
def jruby?
|
143
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
144
|
+
end
|
145
|
+
end # Size
|
146
|
+
end # Screen
|
147
|
+
end # TTY
|
data/lib/tty/screen/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Screen::Color, '.supports?' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
subject(:color) { described_class.new(output: output) }
|
9
|
+
|
10
|
+
it "doesn't check color support for non tty terminal" do
|
11
|
+
allow(output).to receive(:tty?).and_return(false)
|
12
|
+
|
13
|
+
expect(color.supports?).to eq(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "fails to load curses for color support" do
|
17
|
+
allow(color).to receive(:require).with('curses').
|
18
|
+
and_raise(LoadError)
|
19
|
+
|
20
|
+
expect(color.from_curses).to eq(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "loads curses for color support" do
|
24
|
+
allow(color).to receive(:require).with('curses').and_return(true)
|
25
|
+
curses = double(:curses)
|
26
|
+
allow(curses).to receive(:init_screen)
|
27
|
+
allow(curses).to receive(:has_colors?).and_return(true)
|
28
|
+
allow(curses).to receive(:close_screen)
|
29
|
+
|
30
|
+
expect(color.from_curses(curses)).to eql(true)
|
31
|
+
expect(curses).to have_received(:has_colors?)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "fails to find color for dumb terminal" do
|
35
|
+
allow(ENV).to receive(:[]).with('TERM').and_return('dumb')
|
36
|
+
|
37
|
+
expect(color.from_term).to eq(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "inspects term variable for color capabilities" do
|
41
|
+
allow(ENV).to receive(:[]).with('TERM').and_return('xterm')
|
42
|
+
|
43
|
+
expect(color.from_term).to eq(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "inspects color terminal variable for support" do
|
47
|
+
allow(ENV).to receive(:include?).with('COLORTERM').and_return(true)
|
48
|
+
|
49
|
+
expect(color.from_env).to eq(true)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe TTY::Screen, '.new' do
|
6
|
+
let(:output) { StringIO.new('', 'w+') }
|
7
|
+
|
8
|
+
it "initializes size and color detection" do
|
9
|
+
allow(TTY::Screen::Color).to receive(:new).with(output: output)
|
10
|
+
allow(TTY::Screen::Size).to receive(:new).with(output: output)
|
11
|
+
|
12
|
+
TTY::Screen.new(output: output)
|
13
|
+
|
14
|
+
expect(TTY::Screen::Color).to have_received(:new).with(output: output)
|
15
|
+
expect(TTY::Screen::Size).to have_received(:new).with(output: output)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "delegates size call" do
|
19
|
+
size_instance = spy(:size)
|
20
|
+
allow(TTY::Screen::Size).to receive(:new).and_return(size_instance)
|
21
|
+
|
22
|
+
screen = described_class.new
|
23
|
+
screen.size
|
24
|
+
|
25
|
+
expect(size_instance).to have_received(:size)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "allows to call size as class instance" do
|
29
|
+
size_instance = double(:size, size: [51, 280])
|
30
|
+
allow(TTY::Screen::Size).to receive(:new).and_return(size_instance)
|
31
|
+
|
32
|
+
expect(TTY::Screen.size).to eq([51, 280])
|
33
|
+
expect(TTY::Screen.width).to eq(280)
|
34
|
+
expect(TTY::Screen.height).to eq(51)
|
35
|
+
expect(TTY::Screen::Size).to have_received(:new).exactly(3).times
|
36
|
+
end
|
37
|
+
|
38
|
+
it "delegates color call" do
|
39
|
+
color_instance = spy(:color)
|
40
|
+
allow(TTY::Screen::Color).to receive(:new).and_return(color_instance)
|
41
|
+
|
42
|
+
screen = described_class.new
|
43
|
+
screen.color?
|
44
|
+
|
45
|
+
expect(color_instance).to have_received(:supports?)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "allows to call color as class instance" do
|
49
|
+
color_instance = double(:size, supports?: false)
|
50
|
+
allow(TTY::Screen::Color).to receive(:new).and_return(color_instance)
|
51
|
+
|
52
|
+
expect(TTY::Screen.color?).to eq(false)
|
53
|
+
expect(TTY::Screen::Color).to have_received(:new).exactly(1).times
|
54
|
+
end
|
55
|
+
end
|
data/spec/unit/size_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'delegate'
|
5
5
|
|
6
|
-
RSpec.describe TTY::Screen, '.size' do
|
6
|
+
RSpec.describe TTY::Screen::Size, '.size' do
|
7
7
|
class Output < SimpleDelegator
|
8
8
|
def winsize
|
9
9
|
[100, 200]
|
@@ -32,19 +32,9 @@ RSpec.describe TTY::Screen, '.size' do
|
|
32
32
|
it "correctly falls through choices" do
|
33
33
|
allow(screen).to receive(:from_io_console).and_return([51, 280])
|
34
34
|
allow(screen).to receive(:from_readline).and_return(nil)
|
35
|
+
|
35
36
|
expect(screen.size).to eq([51, 280])
|
36
37
|
expect(screen).to_not have_received(:from_readline)
|
37
|
-
expect(screen.width).to eq(280)
|
38
|
-
expect(screen.height).to eq(51)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "allows to call size as class instance" do
|
42
|
-
screen = double(:screen, size: [51, 280])
|
43
|
-
allow(TTY::Screen).to receive(:new).and_return(screen)
|
44
|
-
expect(TTY::Screen.size).to eq([51, 280])
|
45
|
-
expect(TTY::Screen.width).to eq(280)
|
46
|
-
expect(TTY::Screen.height).to eq(51)
|
47
|
-
expect(TTY::Screen).to have_received(:new).exactly(3).times
|
48
38
|
end
|
49
39
|
end
|
50
40
|
|
@@ -56,7 +46,7 @@ RSpec.describe TTY::Screen, '.size' do
|
|
56
46
|
|
57
47
|
it "calcualtes the size" do
|
58
48
|
allow(screen).to receive(:jruby?).and_return(false)
|
59
|
-
allow(
|
49
|
+
allow(screen).to receive(:require).with('io/console').
|
60
50
|
and_return(true)
|
61
51
|
allow(output).to receive(:tty?).and_return(true)
|
62
52
|
allow(IO).to receive(:method_defined?).with(:winsize).and_return(true)
|
@@ -68,14 +58,14 @@ RSpec.describe TTY::Screen, '.size' do
|
|
68
58
|
|
69
59
|
it "doesn't calculate size if io/console not available" do
|
70
60
|
allow(screen).to receive(:jruby?).and_return(false)
|
71
|
-
allow(
|
61
|
+
allow(screen).to receive(:require).with('io/console').
|
72
62
|
and_raise(LoadError)
|
73
63
|
expect(screen.from_io_console).to eq(false)
|
74
64
|
end
|
75
65
|
|
76
66
|
it "doesn't calculate size if it is run without a console" do
|
77
67
|
allow(screen).to receive(:jruby?).and_return(false)
|
78
|
-
allow(
|
68
|
+
allow(screen).to receive(:require).with('io/console').
|
79
69
|
and_return(true)
|
80
70
|
allow(output).to receive(:tty?).and_return(true)
|
81
71
|
allow(IO).to receive(:method_defined?).with(:winsize).and_return(false)
|
data/tty-screen.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = TTY::Screen::VERSION
|
9
9
|
spec.authors = ["Piotr Murach"]
|
10
10
|
spec.email = [""]
|
11
|
-
spec.summary = %q{Terminal screen size detection which works both 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 both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.}
|
11
|
+
spec.summary = %q{Terminal screen size and color detection which works both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.}
|
12
|
+
spec.description = %q{Terminal screen size and color detection which works both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-screen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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: 2015-09-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
-
description: Terminal screen size detection which works both on Linux, OS
|
28
|
-
platforms and supports MRI, JRuby and Rubinius interpreters.
|
27
|
+
description: Terminal screen size and color detection which works both on Linux, OS
|
28
|
+
X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
29
29
|
email:
|
30
30
|
- ''
|
31
31
|
executables: []
|
@@ -43,8 +43,12 @@ files:
|
|
43
43
|
- Rakefile
|
44
44
|
- lib/tty-screen.rb
|
45
45
|
- lib/tty/screen.rb
|
46
|
+
- lib/tty/screen/color.rb
|
47
|
+
- lib/tty/screen/size.rb
|
46
48
|
- lib/tty/screen/version.rb
|
47
49
|
- spec/spec_helper.rb
|
50
|
+
- spec/unit/color_spec.rb
|
51
|
+
- spec/unit/new_spec.rb
|
48
52
|
- spec/unit/size_spec.rb
|
49
53
|
- tasks/console.rake
|
50
54
|
- tasks/coverage.rake
|
@@ -73,9 +77,11 @@ rubyforge_project:
|
|
73
77
|
rubygems_version: 2.0.3
|
74
78
|
signing_key:
|
75
79
|
specification_version: 4
|
76
|
-
summary: Terminal screen size detection which works both on Linux, OS X
|
77
|
-
platforms and supports MRI, JRuby and Rubinius interpreters.
|
80
|
+
summary: Terminal screen size and color detection which works both on Linux, OS X
|
81
|
+
and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
78
82
|
test_files:
|
79
83
|
- spec/spec_helper.rb
|
84
|
+
- spec/unit/color_spec.rb
|
85
|
+
- spec/unit/new_spec.rb
|
80
86
|
- spec/unit/size_spec.rb
|
81
87
|
has_rdoc:
|