tty-screen 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +37 -8
- data/Gemfile +1 -1
- data/README.md +3 -12
- data/lib/tty/screen.rb +6 -17
- data/lib/tty/screen/size.rb +17 -20
- data/lib/tty/screen/version.rb +1 -1
- data/spec/unit/new_spec.rb +23 -26
- data/spec/unit/size_spec.rb +30 -26
- data/tty-screen.gemspec +6 -5
- metadata +27 -10
- data/lib/tty/screen/color.rb +0 -87
- data/spec/unit/color_spec.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be4bc4b46b107018a11b33feebb201553f94c41b
|
4
|
+
data.tar.gz: 377b7c1492d822be260e43f11a7686471dc4b06f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cda3d71ea61b665f0feaefca79def7a255b6d65a5cd067eadf6829d4d3f76953e6ae2b0a6faf93542fc4946dae14cd1c52f24e56f838545ef6b25da2ae86eba
|
7
|
+
data.tar.gz: 6884864fdc21364b397a405b2b99c52aeb8d4dfd0c44f912997a9bca20b2421221c536023b258fcbdb26d78c2b687323bcfba284a740b043b9528241049a75c7
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,26 +1,55 @@
|
|
1
|
-
|
1
|
+
# Change log
|
2
2
|
|
3
|
-
|
3
|
+
## [v0.5.0] - 2016-01-03
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change size to accept environment as input
|
7
|
+
* Remove Color detection, available as tty-color gem dependency
|
8
|
+
|
9
|
+
## [v0.4.3] - 2015-11-01
|
10
|
+
|
11
|
+
### Added
|
4
12
|
* Add NoValue to Color class to mark failure of reading color value
|
13
|
+
|
14
|
+
### Changed
|
5
15
|
* Change Color class supports? to recognize lack of color value
|
6
16
|
|
7
|
-
|
17
|
+
### Fixed
|
18
|
+
* Fix issue with #from_curses method and remove ensure block
|
8
19
|
|
20
|
+
## [v0.4.2] - 2015-10-31
|
21
|
+
|
22
|
+
### Changed
|
9
23
|
* Change visibility of output to prevent warnings
|
10
24
|
|
11
|
-
|
25
|
+
## [v0.4.1] - 2015-10-31
|
12
26
|
|
27
|
+
### Changed
|
13
28
|
* Change to switch off verbose mode by default
|
14
29
|
|
15
|
-
|
30
|
+
## [v0.4.0] - 2015-09-12
|
16
31
|
|
32
|
+
### Added
|
17
33
|
* Add terminal color support detection
|
18
34
|
|
19
|
-
|
35
|
+
## [v0.3.0] - 2015-09-11
|
20
36
|
|
37
|
+
### Fixed
|
21
38
|
* Fix bug loading standard library
|
22
39
|
|
23
|
-
|
40
|
+
## [v0.2.0] - 2015-05-11
|
24
41
|
|
25
|
-
|
42
|
+
### Changed
|
26
43
|
* Change to stop memoization of screen class instance method
|
44
|
+
|
45
|
+
### Fixed
|
46
|
+
* Fix bug with screen detection from_io_console by @luxflux
|
47
|
+
|
48
|
+
[v0.5.0]: https://github.com/peter-murach/tty-screen/compare/v0.4.3...v0.5.0
|
49
|
+
[v0.4.3]: https://github.com/peter-murach/tty-screen/compare/v0.4.2...v0.4.3
|
50
|
+
[v0.4.2]: https://github.com/peter-murach/tty-screen/compare/v0.4.1...v0.4.2
|
51
|
+
[v0.4.1]: https://github.com/peter-murach/tty-screen/compare/v0.4.0...v0.4.1
|
52
|
+
[v0.4.0]: https://github.com/peter-murach/tty-screen/compare/v0.3.0...v0.4.0
|
53
|
+
[v0.3.0]: https://github.com/peter-murach/tty-screen/compare/v0.2.0...v0.3.0
|
54
|
+
[v0.2.0]: https://github.com/peter-murach/tty-screen/compare/v0.1.0...v0.2.0
|
55
|
+
[v0.1.0]: https://github.com/peter-murach/tty-screen/compare/v0.1.0
|
data/Gemfile
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
|
14
|
+
> Terminal screen size detection which works on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
15
15
|
|
16
|
-
**TTY::Screen** provides independent screen size
|
16
|
+
**TTY::Screen** provides independent screen size detection component for [TTY](https://github.com/peter-murach/tty) toolkit.
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -43,21 +43,12 @@ 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
|
-
|
53
46
|
You can also use above methods as class instance methods:
|
54
47
|
|
55
48
|
```ruby
|
56
49
|
TTY::Screen.size # => [51, 280]
|
57
50
|
TTY::Screen.width # => 280
|
58
51
|
TTY::Screen.height # => 51
|
59
|
-
|
60
|
-
TTY::Screen.color? # => true
|
61
52
|
```
|
62
53
|
|
63
54
|
## Contributing
|
@@ -70,4 +61,4 @@ TTY::Screen.color? # => true
|
|
70
61
|
|
71
62
|
## Copyright
|
72
63
|
|
73
|
-
Copyright (c) 2014-
|
64
|
+
Copyright (c) 2014-2016 Piotr Murach. See LICENSE for further details.
|
data/lib/tty/screen.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'tty/screen/color'
|
4
3
|
require 'tty/screen/size'
|
5
4
|
require 'tty/screen/version'
|
6
5
|
|
@@ -19,8 +18,7 @@ module TTY
|
|
19
18
|
def initialize(options = {})
|
20
19
|
@output = options.fetch(:output) { $stderr }
|
21
20
|
@verbose = options.fetch(:verbose) { false }
|
22
|
-
@
|
23
|
-
@size = Size.new(output: @output, verbose: @verbose)
|
21
|
+
@size = Size.new(ENV, output: @output, verbose: @verbose)
|
24
22
|
end
|
25
23
|
|
26
24
|
# @api public
|
@@ -38,10 +36,11 @@ module TTY
|
|
38
36
|
size[0]
|
39
37
|
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
# Terminal size as tuple
|
40
|
+
#
|
41
|
+
# @return [Array[Integer]]
|
42
|
+
#
|
43
|
+
# @api public
|
45
44
|
def size
|
46
45
|
@size.size
|
47
46
|
end
|
@@ -65,15 +64,5 @@ module TTY
|
|
65
64
|
size[1]
|
66
65
|
end
|
67
66
|
alias_method :columns, :width
|
68
|
-
|
69
|
-
# Check if terminal has color support
|
70
|
-
#
|
71
|
-
# @return [Boolean]
|
72
|
-
# true if can display color, false otherwise
|
73
|
-
#
|
74
|
-
# @api public
|
75
|
-
def color?
|
76
|
-
@color.supports?
|
77
|
-
end
|
78
67
|
end # Screen
|
79
68
|
end # TTY
|
data/lib/tty/screen/size.rb
CHANGED
@@ -6,7 +6,8 @@ module TTY
|
|
6
6
|
# Initialize terminal size detection
|
7
7
|
#
|
8
8
|
# @api public
|
9
|
-
def initialize(options = {})
|
9
|
+
def initialize(env, options = {})
|
10
|
+
@env = env
|
10
11
|
@output = options.fetch(:output) { $stderr }
|
11
12
|
@verbose = options.fetch(:verbose) { false }
|
12
13
|
end
|
@@ -34,9 +35,7 @@ module TTY
|
|
34
35
|
# @api private
|
35
36
|
def from_io_console
|
36
37
|
return false if jruby?
|
37
|
-
try_io_console { |size|
|
38
|
-
size if nonzero_column?(size[1])
|
39
|
-
}
|
38
|
+
try_io_console { |size| size if nonzero_column?(size[1]) }
|
40
39
|
end
|
41
40
|
|
42
41
|
# Attempts to load native console extension
|
@@ -45,22 +44,20 @@ module TTY
|
|
45
44
|
#
|
46
45
|
# @api private
|
47
46
|
def try_io_console
|
47
|
+
require 'io/console'
|
48
|
+
|
48
49
|
begin
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if output.tty? && IO.method_defined?(:winsize)
|
53
|
-
yield output.winsize
|
54
|
-
else
|
55
|
-
false
|
56
|
-
end
|
57
|
-
rescue Errno::EOPNOTSUPP
|
50
|
+
if output.tty? && IO.method_defined?(:winsize)
|
51
|
+
yield output.winsize
|
52
|
+
else
|
58
53
|
false
|
59
54
|
end
|
60
|
-
rescue
|
61
|
-
warn 'no native io/console support' if @verbose
|
55
|
+
rescue Errno::EOPNOTSUPP
|
62
56
|
false
|
63
57
|
end
|
58
|
+
rescue LoadError
|
59
|
+
warn 'no native io/console support' if @verbose
|
60
|
+
false
|
64
61
|
end
|
65
62
|
|
66
63
|
# Detect screen size using Readline
|
@@ -98,8 +95,8 @@ module TTY
|
|
98
95
|
#
|
99
96
|
# @api private
|
100
97
|
def from_env
|
101
|
-
return unless
|
102
|
-
size = [(
|
98
|
+
return unless @env['COLUMNS'] =~ /^\d+$/
|
99
|
+
size = [(@env['LINES'] || @env['ROWS']).to_i, @env['COLUMNS'].to_i]
|
103
100
|
size if nonzero_column?(size[1])
|
104
101
|
end
|
105
102
|
|
@@ -107,7 +104,7 @@ module TTY
|
|
107
104
|
#
|
108
105
|
# @api private
|
109
106
|
def from_ansicon
|
110
|
-
return unless
|
107
|
+
return unless @env['ANSICON'] =~ /\((.*)x(.*)\)/
|
111
108
|
size = [$2, $1].map(&:to_i)
|
112
109
|
size if nonzero_column?(size[1])
|
113
110
|
end
|
@@ -117,8 +114,8 @@ module TTY
|
|
117
114
|
# @api public
|
118
115
|
def default_size
|
119
116
|
[
|
120
|
-
|
121
|
-
|
117
|
+
@env['LINES'].to_i.nonzero? || 27,
|
118
|
+
@env['COLUMNS'].to_i.nonzero? || 80
|
122
119
|
]
|
123
120
|
end
|
124
121
|
|
data/lib/tty/screen/version.rb
CHANGED
data/spec/unit/new_spec.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Screen, '.new' do
|
6
|
-
let(:output) { StringIO.new('', 'w+') }
|
7
4
|
|
8
|
-
it "
|
9
|
-
allow(TTY::Screen::
|
10
|
-
|
5
|
+
it "initializses size with defaults" do
|
6
|
+
allow(TTY::Screen::Size).to receive(:new)
|
7
|
+
TTY::Screen.new
|
8
|
+
expect(TTY::Screen::Size).to have_received(:new).
|
9
|
+
with(ENV, {output: $stderr, verbose: false})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "initializes size with values" do
|
13
|
+
allow(TTY::Screen::Size).to receive(:new)
|
11
14
|
|
12
|
-
TTY::Screen.new(output: output)
|
15
|
+
TTY::Screen.new(output: :output, verbose: true)
|
13
16
|
|
14
|
-
expect(TTY::Screen::
|
15
|
-
|
17
|
+
expect(TTY::Screen::Size).to have_received(:new).
|
18
|
+
with(ENV, output: :output, verbose: true)
|
16
19
|
end
|
17
20
|
|
18
21
|
it "delegates size call" do
|
@@ -25,31 +28,25 @@ RSpec.describe TTY::Screen, '.new' do
|
|
25
28
|
expect(size_instance).to have_received(:size)
|
26
29
|
end
|
27
30
|
|
28
|
-
it "
|
31
|
+
it "calls size" do
|
29
32
|
size_instance = double(:size, size: [51, 280])
|
30
33
|
allow(TTY::Screen::Size).to receive(:new).and_return(size_instance)
|
31
34
|
|
32
35
|
expect(TTY::Screen.size).to eq([51, 280])
|
33
|
-
expect(TTY::Screen
|
34
|
-
expect(TTY::Screen.height).to eq(51)
|
35
|
-
expect(TTY::Screen::Size).to have_received(:new).exactly(3).times
|
36
|
+
expect(TTY::Screen::Size).to have_received(:new).once
|
36
37
|
end
|
37
38
|
|
38
|
-
it "
|
39
|
-
|
40
|
-
allow(TTY::Screen::
|
41
|
-
|
42
|
-
screen = described_class.new
|
43
|
-
screen.color?
|
39
|
+
it "calls width" do
|
40
|
+
size_instance = double(:size, size: [51, 280])
|
41
|
+
allow(TTY::Screen::Size).to receive(:new).and_return(size_instance)
|
44
42
|
|
45
|
-
expect(
|
43
|
+
expect(TTY::Screen.width).to eq(280)
|
44
|
+
expect(TTY::Screen::Size).to have_received(:new).once
|
46
45
|
end
|
47
46
|
|
48
|
-
it "
|
49
|
-
|
50
|
-
allow(TTY::Screen::
|
51
|
-
|
52
|
-
expect(TTY::Screen.color?).to eq(false)
|
53
|
-
expect(TTY::Screen::Color).to have_received(:new).exactly(1).times
|
47
|
+
it "calls height" do
|
48
|
+
size_instance = double(:size, size: [51, 280])
|
49
|
+
allow(TTY::Screen::Size).to receive(:new).and_return(size_instance)
|
50
|
+
expect(TTY::Screen.height).to eq(51)
|
54
51
|
end
|
55
52
|
end
|
data/spec/unit/size_spec.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
3
|
require 'delegate'
|
5
4
|
|
6
|
-
RSpec.describe TTY::Screen::Size, '
|
5
|
+
RSpec.describe TTY::Screen::Size, '#size' do
|
7
6
|
class Output < SimpleDelegator
|
8
7
|
def winsize
|
9
8
|
[100, 200]
|
@@ -12,24 +11,9 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
12
11
|
|
13
12
|
let(:output) { Output.new(StringIO.new('', 'w+')) }
|
14
13
|
|
15
|
-
subject(:screen) { described_class.new(output: output) }
|
16
|
-
|
17
|
-
context 'default size' do
|
18
|
-
it "suggests default terminal size" do
|
19
|
-
allow(ENV).to receive(:[]).with('LINES').and_return(0)
|
20
|
-
allow(ENV).to receive(:[]).with('COLUMNS').and_return(0)
|
21
|
-
expect(screen.default_size).to eq([27, 80])
|
22
|
-
end
|
23
|
-
|
24
|
-
it "attempts to get default terminal size from environment" do
|
25
|
-
allow(ENV).to receive(:[]).with('LINES').and_return(52)
|
26
|
-
allow(ENV).to receive(:[]).with('COLUMNS').and_return(200)
|
27
|
-
expect(screen.default_size).to eq([52, 200])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
14
|
context 'size' do
|
32
15
|
it "correctly falls through choices" do
|
16
|
+
screen = described_class.new({}, output: output)
|
33
17
|
allow(screen).to receive(:from_io_console).and_return([51, 280])
|
34
18
|
allow(screen).to receive(:from_readline).and_return(nil)
|
35
19
|
|
@@ -40,11 +24,13 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
40
24
|
|
41
25
|
context 'from io console' do
|
42
26
|
it "doesn't calculate size if jruby " do
|
27
|
+
screen = described_class.new({})
|
43
28
|
allow(screen).to receive(:jruby?).and_return(true)
|
44
29
|
expect(screen.from_io_console).to eq(false)
|
45
30
|
end
|
46
31
|
|
47
32
|
it "calcualtes the size" do
|
33
|
+
screen = described_class.new({}, output: output)
|
48
34
|
allow(screen).to receive(:jruby?).and_return(false)
|
49
35
|
allow(screen).to receive(:require).with('io/console').
|
50
36
|
and_return(true)
|
@@ -57,6 +43,7 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
57
43
|
end
|
58
44
|
|
59
45
|
it "doesn't calculate size if io/console not available" do
|
46
|
+
screen = described_class.new({})
|
60
47
|
allow(screen).to receive(:jruby?).and_return(false)
|
61
48
|
allow(screen).to receive(:require).with('io/console').
|
62
49
|
and_raise(LoadError)
|
@@ -64,6 +51,7 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
64
51
|
end
|
65
52
|
|
66
53
|
it "doesn't calculate size if it is run without a console" do
|
54
|
+
screen = described_class.new({}, output: output)
|
67
55
|
allow(screen).to receive(:jruby?).and_return(false)
|
68
56
|
allow(screen).to receive(:require).with('io/console').
|
69
57
|
and_return(true)
|
@@ -75,11 +63,13 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
75
63
|
|
76
64
|
context 'from tput' do
|
77
65
|
it "doesn't run command if outside of terminal" do
|
66
|
+
screen = described_class.new({}, output: output)
|
78
67
|
allow(output).to receive(:tty?).and_return(false)
|
79
68
|
expect(screen.from_tput).to eq(nil)
|
80
69
|
end
|
81
70
|
|
82
71
|
it "runs tput commands" do
|
72
|
+
screen = described_class.new({}, output: output)
|
83
73
|
allow(output).to receive(:tty?).and_return(true)
|
84
74
|
allow(screen).to receive(:run_command).with('tput', 'lines').and_return(51)
|
85
75
|
allow(screen).to receive(:run_command).with('tput', 'cols').and_return(280)
|
@@ -87,6 +77,7 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
87
77
|
end
|
88
78
|
|
89
79
|
it "doesn't return zero size" do
|
80
|
+
screen = described_class.new({}, output: output)
|
90
81
|
allow(output).to receive(:tty?).and_return(true)
|
91
82
|
allow(screen).to receive(:run_command).with('tput', 'lines').and_return(0)
|
92
83
|
allow(screen).to receive(:run_command).with('tput', 'cols').and_return(0)
|
@@ -96,17 +87,20 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
96
87
|
|
97
88
|
context 'from stty' do
|
98
89
|
it "doesn't run command if outside of terminal" do
|
90
|
+
screen = described_class.new({}, output: output)
|
99
91
|
allow(output).to receive(:tty?).and_return(false)
|
100
92
|
expect(screen.from_stty).to eq(nil)
|
101
93
|
end
|
102
94
|
|
103
95
|
it "runs stty commands" do
|
96
|
+
screen = described_class.new({}, output: output)
|
104
97
|
allow(output).to receive(:tty?).and_return(true)
|
105
98
|
allow(screen).to receive(:run_command).with('stty', 'size').and_return("51 280")
|
106
99
|
expect(screen.from_stty).to eq([51, 280])
|
107
100
|
end
|
108
101
|
|
109
102
|
it "doesn't return zero size" do
|
103
|
+
screen = described_class.new({}, output: output)
|
110
104
|
allow(output).to receive(:tty?).and_return(true)
|
111
105
|
allow(screen).to receive(:run_command).with('stty', 'size').and_return("0 0")
|
112
106
|
expect(screen.from_stty).to eq(nil)
|
@@ -115,37 +109,47 @@ RSpec.describe TTY::Screen::Size, '.size' do
|
|
115
109
|
|
116
110
|
context 'from env' do
|
117
111
|
it "doesn't calculate size without COLUMNS key" do
|
118
|
-
|
112
|
+
screen = described_class.new({'COLUMNS' => nil})
|
119
113
|
expect(screen.from_env).to eq(nil)
|
120
114
|
end
|
121
115
|
|
122
116
|
it "extracts lines and columns from environment" do
|
123
|
-
|
124
|
-
allow(ENV).to receive(:[]).with('LINES').and_return("51")
|
117
|
+
screen = described_class.new({'COLUMNS' => '280', 'LINES' => '51'})
|
125
118
|
expect(screen.from_env).to eq([51, 280])
|
126
119
|
end
|
127
120
|
|
128
121
|
it "doesn't return zero size" do
|
129
|
-
|
130
|
-
allow(ENV).to receive(:[]).with('LINES').and_return("0")
|
122
|
+
screen = described_class.new({'COLUMNS' => '0', 'LINES' => '0'})
|
131
123
|
expect(screen.from_env).to eq(nil)
|
132
124
|
end
|
133
125
|
end
|
134
126
|
|
135
127
|
context 'from ansicon' do
|
136
128
|
it "doesn't calculate size without ANSICON key" do
|
137
|
-
|
129
|
+
screen = described_class.new({'ANSICON' => nil})
|
138
130
|
expect(screen.from_ansicon).to eq(nil)
|
139
131
|
end
|
140
132
|
|
141
133
|
it "extracts lines and columns from environment" do
|
142
|
-
|
134
|
+
screen = described_class.new({'ANSICON' => '(280x51)'})
|
143
135
|
expect(screen.from_ansicon).to eq([51, 280])
|
144
136
|
end
|
145
137
|
|
146
138
|
it "doesn't return zero size" do
|
147
|
-
|
139
|
+
screen = described_class.new({'ANSICON' => '(0x0)'})
|
148
140
|
expect(screen.from_ansicon).to eq(nil)
|
149
141
|
end
|
150
142
|
end
|
143
|
+
|
144
|
+
context 'default size' do
|
145
|
+
it "suggests default terminal size" do
|
146
|
+
screen = described_class.new({'LINES' => 0, 'COLUMNS' => 0})
|
147
|
+
expect(screen.default_size).to eq([27, 80])
|
148
|
+
end
|
149
|
+
|
150
|
+
it "attempts to get default terminal size from environment" do
|
151
|
+
screen = described_class.new({'LINES' => 52, 'COLUMNS' => 200})
|
152
|
+
expect(screen.default_size).to eq([52, 200])
|
153
|
+
end
|
154
|
+
end
|
151
155
|
end
|
data/tty-screen.gemspec
CHANGED
@@ -4,19 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'tty/screen/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'tty-screen'
|
8
8
|
spec.version = TTY::Screen::VERSION
|
9
9
|
spec.authors = ["Piotr Murach"]
|
10
10
|
spec.email = [""]
|
11
|
-
spec.summary = %q{Terminal screen size
|
12
|
-
spec.description = %q{Terminal screen size
|
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
13
|
spec.homepage = "http://peter-murach.github.io/tty/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
23
|
end
|
metadata
CHANGED
@@ -1,31 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-screen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2016-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.0
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.0
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
16
36
|
requirements:
|
17
37
|
- - ~>
|
18
38
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
39
|
+
version: '10.0'
|
20
40
|
type: :development
|
21
41
|
prerelease: false
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
23
43
|
requirements:
|
24
44
|
- - ~>
|
25
45
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
description: Terminal screen size
|
28
|
-
|
46
|
+
version: '10.0'
|
47
|
+
description: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
|
48
|
+
platforms and supports MRI, JRuby and Rubinius interpreters.
|
29
49
|
email:
|
30
50
|
- ''
|
31
51
|
executables: []
|
@@ -43,11 +63,9 @@ files:
|
|
43
63
|
- Rakefile
|
44
64
|
- lib/tty-screen.rb
|
45
65
|
- lib/tty/screen.rb
|
46
|
-
- lib/tty/screen/color.rb
|
47
66
|
- lib/tty/screen/size.rb
|
48
67
|
- lib/tty/screen/version.rb
|
49
68
|
- spec/spec_helper.rb
|
50
|
-
- spec/unit/color_spec.rb
|
51
69
|
- spec/unit/new_spec.rb
|
52
70
|
- spec/unit/size_spec.rb
|
53
71
|
- tasks/console.rake
|
@@ -77,11 +95,10 @@ rubyforge_project:
|
|
77
95
|
rubygems_version: 2.0.3
|
78
96
|
signing_key:
|
79
97
|
specification_version: 4
|
80
|
-
summary: Terminal screen size
|
98
|
+
summary: Terminal screen size detection which works on Linux, OS X and Windows/Cygwin
|
81
99
|
platforms and supports MRI, JRuby and Rubinius interpreters.
|
82
100
|
test_files:
|
83
101
|
- spec/spec_helper.rb
|
84
|
-
- spec/unit/color_spec.rb
|
85
102
|
- spec/unit/new_spec.rb
|
86
103
|
- spec/unit/size_spec.rb
|
87
104
|
has_rdoc:
|
data/lib/tty/screen/color.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module TTY
|
4
|
-
class Screen
|
5
|
-
class Color
|
6
|
-
NoValue = Module.new
|
7
|
-
|
8
|
-
# Initialize color support
|
9
|
-
#
|
10
|
-
# @api public
|
11
|
-
def initialize(options = {})
|
12
|
-
@output = options.fetch(:output) { $stderr }
|
13
|
-
@verbose = options.fetch(:verbose) { false }
|
14
|
-
end
|
15
|
-
|
16
|
-
# Detect if terminal supports color
|
17
|
-
#
|
18
|
-
# @return [Boolean]
|
19
|
-
# true when terminal supports color, false otherwise
|
20
|
-
#
|
21
|
-
# @api public
|
22
|
-
def supports?
|
23
|
-
return false unless tty?
|
24
|
-
|
25
|
-
value = false
|
26
|
-
%w(from_curses from_tput from_term from_env).each do |from_check|
|
27
|
-
break if (value = public_send(from_check)) != NoValue
|
28
|
-
end
|
29
|
-
return false if value == NoValue
|
30
|
-
value
|
31
|
-
end
|
32
|
-
|
33
|
-
# Attempt to load curses to check color support
|
34
|
-
#
|
35
|
-
# @return [Boolean]
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
def from_curses(curses_class = nil)
|
39
|
-
require 'curses'
|
40
|
-
|
41
|
-
if defined?(Curses)
|
42
|
-
curses_class ||= Curses
|
43
|
-
curses_class.init_screen
|
44
|
-
has_color = curses_class.has_colors?
|
45
|
-
curses_class.close_screen
|
46
|
-
has_color
|
47
|
-
else
|
48
|
-
NoValue
|
49
|
-
end
|
50
|
-
rescue LoadError
|
51
|
-
warn 'no native curses support' if @verbose
|
52
|
-
NoValue
|
53
|
-
end
|
54
|
-
|
55
|
-
# Shell out to tput to check color support
|
56
|
-
#
|
57
|
-
# @api private
|
58
|
-
def from_tput
|
59
|
-
%x(tput colors 2>/dev/null).to_i > 2
|
60
|
-
rescue Errno::ENOENT
|
61
|
-
NoValue
|
62
|
-
end
|
63
|
-
|
64
|
-
# Inspect environment $TERM variable for color support
|
65
|
-
#
|
66
|
-
# @api private
|
67
|
-
def from_term
|
68
|
-
if ENV['TERM'] == 'dumb'
|
69
|
-
false
|
70
|
-
elsif ENV['TERM'] =~ /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i
|
71
|
-
true
|
72
|
-
else NoValue
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def from_env
|
77
|
-
ENV.include?('COLORTERM')
|
78
|
-
end
|
79
|
-
|
80
|
-
attr_reader :output
|
81
|
-
|
82
|
-
def tty?
|
83
|
-
output.tty?
|
84
|
-
end
|
85
|
-
end # Color
|
86
|
-
end # Screen
|
87
|
-
end # TTY
|
data/spec/unit/color_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
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(described_class::NoValue)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "loads curses for color support" do
|
24
|
-
allow(color).to receive(:require).with('curses').and_return(true)
|
25
|
-
stub_const("Curses", Object.new)
|
26
|
-
curses = double(:curses)
|
27
|
-
allow(curses).to receive(:init_screen)
|
28
|
-
allow(curses).to receive(:has_colors?).and_return(true)
|
29
|
-
allow(curses).to receive(:close_screen)
|
30
|
-
|
31
|
-
expect(color.from_curses(curses)).to eql(true)
|
32
|
-
expect(curses).to have_received(:has_colors?)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "fails to find color for dumb terminal" do
|
36
|
-
allow(ENV).to receive(:[]).with('TERM').and_return('dumb')
|
37
|
-
|
38
|
-
expect(color.from_term).to eq(false)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "inspects term variable for color capabilities" do
|
42
|
-
allow(ENV).to receive(:[]).with('TERM').and_return('xterm')
|
43
|
-
|
44
|
-
expect(color.from_term).to eq(true)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "inspects color terminal variable for support" do
|
48
|
-
allow(ENV).to receive(:include?).with('COLORTERM').and_return(true)
|
49
|
-
|
50
|
-
expect(color.from_env).to eq(true)
|
51
|
-
end
|
52
|
-
end
|