tty-screen 0.1.0 → 0.2.0
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 +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -1
- data/README.md +4 -2
- data/lib/tty/screen.rb +41 -27
- data/lib/tty/screen/version.rb +1 -1
- data/spec/unit/size_spec.rb +8 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b0fdd11a1c93555dd997f4ba8c6068d6004323
|
4
|
+
data.tar.gz: 8d2c77d63960973eee13221cff921e3ba4969837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ed7d421d44185fa600b3c7ff22b91f44947a90194ebcc29682692f4e5f4df9287c7f33ec4932124302724791404414eac773e17ac667ef7a3daf18ed8cc22e
|
7
|
+
data.tar.gz: 8075b1853ff419e7690a92ef7ee81436195ba3fd8c52dd41b1b87713028d445cad6a6a5394de04fec3f59aaaedf76db7449bb78b56cf732e0343b9bb7a8409fe
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -44,7 +44,9 @@ screen.height # => 51
|
|
44
44
|
You can also use above methods as class instance methods:
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
TTY::Screen.size
|
47
|
+
TTY::Screen.size # => [51, 280]
|
48
|
+
TTY::Screen.width # => 280
|
49
|
+
TTY::Screen.height # => 51
|
48
50
|
```
|
49
51
|
|
50
52
|
## Contributing
|
@@ -57,4 +59,4 @@ TTY::Screen.size # => [51, 280]
|
|
57
59
|
|
58
60
|
## Copyright
|
59
61
|
|
60
|
-
Copyright (c) 2014 Piotr Murach. See LICENSE for further details.
|
62
|
+
Copyright (c) 2014-2015 Piotr Murach. See LICENSE for further details.
|
data/lib/tty/screen.rb
CHANGED
@@ -7,11 +7,6 @@ module TTY
|
|
7
7
|
#
|
8
8
|
# @api public
|
9
9
|
class Screen
|
10
|
-
# Specifies an output stream object
|
11
|
-
#
|
12
|
-
# @api public
|
13
|
-
attr_reader :output
|
14
|
-
|
15
10
|
# Create terminal screen
|
16
11
|
#
|
17
12
|
# @param [Hash] options
|
@@ -23,36 +18,21 @@ module TTY
|
|
23
18
|
@output = options.fetch(:output) { $stderr }
|
24
19
|
end
|
25
20
|
|
21
|
+
# @api public
|
26
22
|
def self.size
|
27
|
-
|
23
|
+
new.size
|
28
24
|
end
|
29
25
|
|
26
|
+
# @api public
|
30
27
|
def self.width
|
31
28
|
size[1]
|
32
29
|
end
|
33
30
|
|
31
|
+
# @api public
|
34
32
|
def self.height
|
35
33
|
size[0]
|
36
34
|
end
|
37
35
|
|
38
|
-
# Get terminal rows and columns
|
39
|
-
#
|
40
|
-
# @return [Array[Integer, Integer]]
|
41
|
-
# return rows & columns
|
42
|
-
#
|
43
|
-
# @api public
|
44
|
-
def size
|
45
|
-
@size ||= begin
|
46
|
-
size = from_io_console
|
47
|
-
size ||= from_readline
|
48
|
-
size ||= from_tput
|
49
|
-
size ||= from_stty
|
50
|
-
size ||= from_env
|
51
|
-
size ||= from_ansicon
|
52
|
-
size || default_size
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
36
|
# Default terminal size
|
57
37
|
#
|
58
38
|
# @api public
|
@@ -60,16 +40,44 @@ module TTY
|
|
60
40
|
[27, 80]
|
61
41
|
end
|
62
42
|
|
43
|
+
# Terminal lines count
|
44
|
+
#
|
45
|
+
# @return [Integer]
|
46
|
+
#
|
47
|
+
# @api public
|
63
48
|
def height
|
64
49
|
size[0]
|
65
50
|
end
|
66
51
|
alias_method :rows, :height
|
67
52
|
|
53
|
+
# Terminal columns count
|
54
|
+
#
|
55
|
+
# @return [Integer]
|
56
|
+
#
|
57
|
+
# @api public
|
68
58
|
def width
|
69
59
|
size[1]
|
70
60
|
end
|
71
61
|
alias_method :columns, :width
|
72
62
|
|
63
|
+
# Get terminal rows and columns
|
64
|
+
#
|
65
|
+
# @return [Array[Integer, Integer]]
|
66
|
+
# return rows & columns
|
67
|
+
#
|
68
|
+
# @api public
|
69
|
+
def size
|
70
|
+
@size ||= begin
|
71
|
+
size = from_io_console
|
72
|
+
size ||= from_readline
|
73
|
+
size ||= from_tput
|
74
|
+
size ||= from_stty
|
75
|
+
size ||= from_env
|
76
|
+
size ||= from_ansicon
|
77
|
+
size || default_size
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
73
81
|
# Detect screen size by loading io/console lib
|
74
82
|
#
|
75
83
|
# @return [Array[Integer, Integer]]
|
@@ -78,6 +86,7 @@ module TTY
|
|
78
86
|
def from_io_console
|
79
87
|
return if jruby?
|
80
88
|
Kernel.require 'io/console'
|
89
|
+
return unless IO.respond_to?(:console)
|
81
90
|
size = IO.console.winsize
|
82
91
|
size if nonzero_column?(size[1])
|
83
92
|
rescue LoadError
|
@@ -134,15 +143,20 @@ module TTY
|
|
134
143
|
size if nonzero_column?(size[1])
|
135
144
|
end
|
136
145
|
|
137
|
-
|
146
|
+
private
|
147
|
+
|
148
|
+
# Specifies an output stream object
|
138
149
|
#
|
139
150
|
# @api public
|
151
|
+
attr_reader :output
|
152
|
+
|
153
|
+
# Runs command in subprocess
|
154
|
+
#
|
155
|
+
# @api private
|
140
156
|
def run_command(command, name)
|
141
157
|
`#{command} #{name} 2>/dev/null`
|
142
158
|
end
|
143
159
|
|
144
|
-
private
|
145
|
-
|
146
160
|
def nonzero_column?(column)
|
147
161
|
column.to_i > 0
|
148
162
|
end
|
data/lib/tty/screen/version.rb
CHANGED
data/spec/unit/size_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe TTY::Screen, '.size' do
|
@@ -19,10 +21,9 @@ RSpec.describe TTY::Screen, '.size' do
|
|
19
21
|
screen = double(:screen, size: [51, 280])
|
20
22
|
allow(TTY::Screen).to receive(:new).and_return(screen)
|
21
23
|
expect(TTY::Screen.size).to eq([51, 280])
|
22
|
-
expect(TTY::Screen.size).to eq([51, 280])
|
23
24
|
expect(TTY::Screen.width).to eq(280)
|
24
25
|
expect(TTY::Screen.height).to eq(51)
|
25
|
-
expect(TTY::Screen).to have_received(:new).
|
26
|
+
expect(TTY::Screen).to have_received(:new).exactly(3).times
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -37,6 +38,11 @@ RSpec.describe TTY::Screen, '.size' do
|
|
37
38
|
allow(Kernel).to receive(:require).with('io/console').and_raise(LoadError)
|
38
39
|
expect(screen.from_io_console).to eq(nil)
|
39
40
|
end
|
41
|
+
|
42
|
+
it "doesn't calculate size if it is run without a console" do
|
43
|
+
allow(IO).to receive(:respond_to?).with(:console).and_return(false)
|
44
|
+
expect(screen.from_io_console).to eq(nil)
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
context 'from tput' do
|
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.2.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: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- .rspec
|
37
37
|
- .ruby-version
|
38
38
|
- .travis.yml
|
39
|
+
- CHANGELOG.md
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|