tty-screen 0.2.0 → 0.3.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 +4 -0
- data/Gemfile +4 -5
- data/README.md +6 -4
- data/lib/tty/screen.rb +36 -13
- data/lib/tty/screen/version.rb +1 -1
- data/spec/unit/size_spec.rb +44 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a06a8743f9b9c8201505e62561368c0ee30173
|
4
|
+
data.tar.gz: 5076f6033f0be8495506a2585bd551697eeff316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8659b0a56e2b205ebcd8793a0005ab7c48c91eb32fb336c96dff63ea1823ab02cbb74e9a0451e19246b13924ecd545b9366c3efc7fb7dfc97e3aaebd985c9cdd
|
7
|
+
data.tar.gz: 1f8600f8c43ae74fb85862abb98fae26537551db81b1f35a086d3cfee2b53a44c62fcc208ec72222ce38a1065cb94a4c7d7580676279c4a0d8c967e3b934b93c
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -3,14 +3,13 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem 'rake', '~> 10.
|
7
|
-
gem 'rspec', '~> 3.
|
6
|
+
gem 'rake', '~> 10.4.2'
|
7
|
+
gem 'rspec', '~> 3.3.0'
|
8
8
|
gem 'yard', '~> 0.8.7'
|
9
|
-
gem 'timecop', '~> 0.7.1'
|
10
9
|
end
|
11
10
|
|
12
11
|
group :metrics do
|
13
|
-
gem 'coveralls', '~> 0.
|
14
|
-
gem 'simplecov', '~> 0.
|
12
|
+
gem 'coveralls', '~> 0.8.1'
|
13
|
+
gem 'simplecov', '~> 0.10.0'
|
15
14
|
gem 'yardstick', '~> 0.9.9'
|
16
15
|
end
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# TTY::Screen
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/tty-screen.
|
3
|
-
[![Build Status](https://secure.travis-ci.org/peter-murach/tty-screen.
|
4
|
-
[![Code Climate](https://codeclimate.com/github/peter-murach/tty-screen.
|
5
|
-
[![Coverage Status](https://coveralls.io/repos/peter-murach/tty-screen/badge.
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/tty-screen.svg)][gem]
|
3
|
+
[![Build Status](https://secure.travis-ci.org/peter-murach/tty-screen.svg?branch=master)][travis]
|
4
|
+
[![Code Climate](https://codeclimate.com/github/peter-murach/tty-screen/badges/gpa.svg)][codeclimate]
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/peter-murach/tty-screen/badge.svg)][coverage]
|
6
|
+
[![Inline docs](http://inch-ci.org/github/peter-murach/tty-screen.svg?branch=master)][inchpages]
|
6
7
|
|
7
8
|
[gem]: http://badge.fury.io/rb/tty-screen
|
8
9
|
[travis]: http://travis-ci.org/peter-murach/tty-screen
|
9
10
|
[codeclimate]: https://codeclimate.com/github/peter-murach/tty-screen
|
10
11
|
[coverage]: https://coveralls.io/r/peter-murach/tty-screen
|
12
|
+
[inchpages]: http://inch-ci.org/github/peter-murach/tty-screen
|
11
13
|
|
12
14
|
> Terminal screen size detection which works both on Linux, OS X and Windows/Cygwin platforms and supports MRI, JRuby and Rubinius interpreters.
|
13
15
|
|
data/lib/tty/screen.rb
CHANGED
@@ -37,7 +37,10 @@ module TTY
|
|
37
37
|
#
|
38
38
|
# @api public
|
39
39
|
def default_size
|
40
|
-
[
|
40
|
+
[
|
41
|
+
ENV['LINES'].to_i.nonzero? || 27,
|
42
|
+
ENV['COLUMNS'].to_i.nonzero? || 80
|
43
|
+
]
|
41
44
|
end
|
42
45
|
|
43
46
|
# Terminal lines count
|
@@ -84,17 +87,37 @@ module TTY
|
|
84
87
|
#
|
85
88
|
# @api private
|
86
89
|
def from_io_console
|
87
|
-
return if jruby?
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
size if nonzero_column?(size[1])
|
92
|
-
rescue LoadError
|
93
|
-
# Didn't find io/console in stdlib
|
90
|
+
return false if jruby?
|
91
|
+
try_io_console { |size|
|
92
|
+
size if nonzero_column?(size[1])
|
93
|
+
}
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
96
|
+
# Attempts to load native console extension
|
97
|
+
#
|
98
|
+
# @return [Boolean, Array]
|
97
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
|
98
121
|
#
|
99
122
|
# @api private
|
100
123
|
def from_readline
|
@@ -106,7 +129,7 @@ module TTY
|
|
106
129
|
|
107
130
|
# Detect terminal size from tput utility
|
108
131
|
#
|
109
|
-
# @api
|
132
|
+
# @api private
|
110
133
|
def from_tput
|
111
134
|
return unless output.tty?
|
112
135
|
lines = run_command('tput', 'lines').to_i
|
@@ -117,7 +140,7 @@ module TTY
|
|
117
140
|
|
118
141
|
# Detect terminal size from stty utility
|
119
142
|
#
|
120
|
-
# @api
|
143
|
+
# @api private
|
121
144
|
def from_stty
|
122
145
|
return unless output.tty?
|
123
146
|
size = run_command('stty', 'size').split.map(&:to_i)
|
@@ -153,8 +176,8 @@ module TTY
|
|
153
176
|
# Runs command in subprocess
|
154
177
|
#
|
155
178
|
# @api private
|
156
|
-
def run_command(command,
|
157
|
-
`#{command} #{
|
179
|
+
def run_command(command, *args)
|
180
|
+
`#{command} #{args.join(' ')} 2>/dev/null`
|
158
181
|
end
|
159
182
|
|
160
183
|
def nonzero_column?(column)
|
data/lib/tty/screen/version.rb
CHANGED
data/spec/unit/size_spec.rb
CHANGED
@@ -1,12 +1,33 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require 'delegate'
|
4
5
|
|
5
6
|
RSpec.describe TTY::Screen, '.size' do
|
6
|
-
|
7
|
+
class Output < SimpleDelegator
|
8
|
+
def winsize
|
9
|
+
[100, 200]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:output) { Output.new(StringIO.new('', 'w+')) }
|
7
14
|
|
8
15
|
subject(:screen) { described_class.new(output: output) }
|
9
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
|
+
|
10
31
|
context 'size' do
|
11
32
|
it "correctly falls through choices" do
|
12
33
|
allow(screen).to receive(:from_io_console).and_return([51, 280])
|
@@ -30,18 +51,35 @@ RSpec.describe TTY::Screen, '.size' do
|
|
30
51
|
context 'from io console' do
|
31
52
|
it "doesn't calculate size if jruby " do
|
32
53
|
allow(screen).to receive(:jruby?).and_return(true)
|
33
|
-
expect(screen.from_io_console).to eq(
|
54
|
+
expect(screen.from_io_console).to eq(false)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "calcualtes the size" do
|
58
|
+
allow(screen).to receive(:jruby?).and_return(false)
|
59
|
+
allow(TTY::Screen).to receive(:require).with('io/console').
|
60
|
+
and_return(true)
|
61
|
+
allow(output).to receive(:tty?).and_return(true)
|
62
|
+
allow(IO).to receive(:method_defined?).with(:winsize).and_return(true)
|
63
|
+
allow(output).to receive(:winsize).and_return([100, 200])
|
64
|
+
|
65
|
+
expect(screen.from_io_console).to eq([100, 200])
|
66
|
+
expect(output).to have_received(:winsize)
|
34
67
|
end
|
35
68
|
|
36
69
|
it "doesn't calculate size if io/console not available" do
|
37
70
|
allow(screen).to receive(:jruby?).and_return(false)
|
38
|
-
allow(
|
39
|
-
|
71
|
+
allow(TTY::Screen).to receive(:require).with('io/console').
|
72
|
+
and_raise(LoadError)
|
73
|
+
expect(screen.from_io_console).to eq(false)
|
40
74
|
end
|
41
75
|
|
42
76
|
it "doesn't calculate size if it is run without a console" do
|
43
|
-
allow(
|
44
|
-
|
77
|
+
allow(screen).to receive(:jruby?).and_return(false)
|
78
|
+
allow(TTY::Screen).to receive(:require).with('io/console').
|
79
|
+
and_return(true)
|
80
|
+
allow(output).to receive(:tty?).and_return(true)
|
81
|
+
allow(IO).to receive(:method_defined?).with(:winsize).and_return(false)
|
82
|
+
expect(screen.from_io_console).to eq(false)
|
45
83
|
end
|
46
84
|
end
|
47
85
|
|
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.3.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-
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|