tty 0.1.3 → 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/CHANGELOG.md +6 -0
- data/Gemfile +4 -4
- data/README.md +72 -47
- data/lib/tty.rb +4 -5
- data/lib/tty/system.rb +0 -48
- data/lib/tty/terminal.rb +0 -18
- data/lib/tty/terminal/echo.rb +2 -2
- data/lib/tty/terminal/raw.rb +2 -2
- data/lib/tty/version.rb +1 -1
- data/tty.gemspec +6 -3
- metadata +48 -30
- data/lib/tty/system/which.rb +0 -51
- data/lib/tty/terminal/pager.rb +0 -96
- data/lib/tty/terminal/pager/basic.rb +0 -49
- data/lib/tty/terminal/pager/system.rb +0 -36
- data/spec/tty/system/platform_spec.rb +0 -46
- data/spec/tty/system/which/which_spec.rb +0 -48
- data/spec/tty/system/which_spec.rb +0 -15
- data/spec/tty/terminal/page_spec.rb +0 -14
- data/spec/tty/terminal/pager/available_spec.rb +0 -40
- data/spec/tty/terminal/pager/basic/page_spec.rb +0 -54
- data/spec/tty/terminal/pager/command_spec.rb +0 -16
- data/spec/tty/terminal/pager/executables_spec.rb +0 -13
- data/spec/tty/terminal/pager/page_spec.rb +0 -45
- data/spec/tty/terminal/pager/system/page_spec.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adb46f2f2927f1568a05f2bd72a95716463b325b
|
4
|
+
data.tar.gz: 9d51b87df30a5743b6c72685685e085fe52f4d4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b759a9417dd3cdd4ecc2f306b07eb9e47479e45bd4d5d54669157ef357491e55f6bc2c32cb061c9e6e6f31d3a85b21904e7665a6d9decfc8f2e991e93718562e
|
7
|
+
data.tar.gz: 444c56543b529c9e22b5b90b557a0398be12c2270223d7b97dc4732972380ea7838a9897e6a2a0d50a8ada2e34390e60f38a7c6f3240640ffba57539c0073204
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.2.0 (July 6, 2015)
|
2
|
+
|
3
|
+
* Extract platform detection as dependency on tty-platform
|
4
|
+
* Extract terminal output paging as dependency on tty-pager
|
5
|
+
* Extract which command as dependency on tty-which
|
6
|
+
|
1
7
|
0.1.3 (April 3, 2015)
|
2
8
|
|
3
9
|
* Add table rendering as dependency on tty-table
|
data/Gemfile
CHANGED
@@ -3,15 +3,15 @@ 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.2.0'
|
8
8
|
gem 'yard', '~> 0.8.7'
|
9
9
|
gem 'timecop', '~> 0.7.1'
|
10
10
|
end
|
11
11
|
|
12
12
|
group :metrics do
|
13
|
-
gem 'coveralls', '~> 0.
|
14
|
-
gem 'simplecov', '~> 0.
|
13
|
+
gem 'coveralls', '~> 0.8.1'
|
14
|
+
gem 'simplecov', '~> 0.10.0'
|
15
15
|
gem 'yardstick', '~> 0.9.9'
|
16
16
|
gem 'reek', '~> 1.3.7'
|
17
17
|
end
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# [][icon]
|
2
2
|
[icon]: http://peter-murach.github.io/tty/
|
3
|
-
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][codeclimate]
|
6
|
+
[][coveralls]
|
7
|
+
[][inchpages]
|
8
8
|
[][gitter]
|
9
9
|
|
10
10
|
[gem]: http://badge.fury.io/rb/tty
|
@@ -57,17 +57,18 @@ Or install it yourself as:
|
|
57
57
|
|
58
58
|
## Contents
|
59
59
|
|
60
|
-
* [1.
|
61
|
-
* [2.
|
62
|
-
* [3.
|
63
|
-
* [4.
|
64
|
-
* [5.
|
65
|
-
* [6.
|
66
|
-
|
67
|
-
* [
|
68
|
-
* [
|
60
|
+
* [1. Overview](#1-overview)
|
61
|
+
* [2. Drawing tables](#2-drawing-tables)
|
62
|
+
* [3. Drawing progress bars](#3-drawing-progress-bars)
|
63
|
+
* [4. Drawing spinners](#4-drawing-spinners)
|
64
|
+
* [5. Output coloring](#5-output-coloring)
|
65
|
+
* [6. Output paging](#6-output-paging)
|
66
|
+
* [7. Detecting screen properties](#7-detecting-screen-properties)
|
67
|
+
* [8. Detecting platform](#8-detecting-platform)
|
68
|
+
* [9. Searching executables](#9-searching-executables)
|
69
|
+
* [10. Prompting for input](#10-prompting-for-input)
|
69
70
|
|
70
|
-
##
|
71
|
+
## 1. Overview
|
71
72
|
|
72
73
|
**TTY** provides you with many tools to get the job done in terminal.
|
73
74
|
|
@@ -110,7 +111,7 @@ screen.width # => 280
|
|
110
111
|
screen.height # => 51
|
111
112
|
```
|
112
113
|
|
113
|
-
##
|
114
|
+
## 2. Drawing tables
|
114
115
|
|
115
116
|
**TTY** uses the [tty-table](https://github.com/peter-murach/tty-table) component in order to convert data into table and render as string output in tabular form. For example, to render data with ASCII border:
|
116
117
|
|
@@ -128,20 +129,11 @@ table.render(:ascii)
|
|
128
129
|
|
129
130
|
Please refer to [documentation](https://github.com/peter-murach/tty-table) for complete API.
|
130
131
|
|
131
|
-
##
|
132
|
+
## 3. Drawing progress bars
|
132
133
|
|
133
|
-
In order to
|
134
|
-
|
135
|
-
```ruby
|
136
|
-
pastel = Pastel.new
|
137
|
-
pastel.red.on_green.bold 'text...' # => red bold text on green background
|
138
|
-
```
|
139
|
-
|
140
|
-
Please refer to [documentation](https://github.com/peter-murach/pastel) for complete API.
|
134
|
+
In order to draw progress bars in terminal, **TTY** uses the [tty-progressbar](https://github.com/peter-murach/tty-progressbar) component.
|
141
135
|
|
142
|
-
|
143
|
-
|
144
|
-
In order to draw progress bar **TTY** uses the [tty-progressbar](https://github.com/peter-murach/tty-progressbar) component. For example, to render basic download bar do:
|
136
|
+
For example, to render basic download bar do:
|
145
137
|
|
146
138
|
```ruby
|
147
139
|
bar = TTY::ProgressBar.new("downloading [:bar]", total: 30)
|
@@ -150,7 +142,7 @@ bar = TTY::ProgressBar.new("downloading [:bar]", total: 30)
|
|
150
142
|
|
151
143
|
Please refer to [documentation](https://github.com/peter-murach/tty-progressbar) for complete API.
|
152
144
|
|
153
|
-
## 4.
|
145
|
+
## 4. Drawing spinners
|
154
146
|
|
155
147
|
**TTY** uses the [tty-spinner](https://github.com/peter-murach/tty-spinner) component to handle terminal spinning animation. For instance, to create a simple spinner do:
|
156
148
|
|
@@ -161,9 +153,35 @@ spinner = TTY::Spinner.new('Loading ... ', format: :spin_2)
|
|
161
153
|
|
162
154
|
Please refer to [documentation](https://github.com/peter-murach/tty-spinner) for complete API.
|
163
155
|
|
164
|
-
## 5.
|
156
|
+
## 5. Output coloring
|
157
|
+
|
158
|
+
In order to colorize your output **TTY** uses the [pastel](https://github.com/peter-murach/pastel) component like so:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
pastel = Pastel.new
|
162
|
+
pastel.red.on_green.bold 'text...' # => red bold text on green background
|
163
|
+
```
|
164
|
+
|
165
|
+
Please refer to [documentation](https://github.com/peter-murach/pastel) for complete API.
|
166
|
+
|
167
|
+
## 6. Output paging
|
165
168
|
|
166
|
-
**TTY**
|
169
|
+
To page terminal output **TTY** relies on [tty-pager](https://github.com/peter-murach/tty-pager) component.
|
170
|
+
|
171
|
+
For example to page terminal output do (on non unix systems falls back to ruby implementation):
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
pager = TTY::Pager.new
|
175
|
+
pager.page('Very long text...')
|
176
|
+
```
|
177
|
+
|
178
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-pager) for complete API.
|
179
|
+
|
180
|
+
## 7. Detecting screen properties
|
181
|
+
|
182
|
+
**TTY** uses the [tty-screen](https://github.com/peter-murach/tty-screen) component to measure the screen properties.
|
183
|
+
|
184
|
+
For example to get screen size do:
|
167
185
|
|
168
186
|
```ruby
|
169
187
|
screen = TTY::Screen.new
|
@@ -174,25 +192,39 @@ screen.height # => 51
|
|
174
192
|
|
175
193
|
Please refer to [documentation](https://github.com/peter-murach/tty-screen) for complete API.
|
176
194
|
|
177
|
-
##
|
195
|
+
## 8. Detecting platform
|
178
196
|
|
179
|
-
To
|
197
|
+
To check for platform properties **TTY** uses [tty-platform](https://github.com/peter-murach/tty-platform) component.
|
180
198
|
|
181
199
|
```ruby
|
182
|
-
|
183
|
-
|
184
|
-
|
200
|
+
platform = TTY::Platform.new
|
201
|
+
platform.cpu # => 'x86_64'
|
202
|
+
platform.os # => 'darwin'
|
203
|
+
platform.version # => '10.6.1'
|
185
204
|
```
|
186
205
|
|
187
|
-
|
206
|
+
In addition, there are more generic utilities to check for type of operating system:
|
188
207
|
|
189
|
-
|
208
|
+
```
|
209
|
+
TTY::Platform.unix? # => true
|
210
|
+
TTY::Platform.windows? # => false
|
211
|
+
```
|
212
|
+
|
213
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-platform) for complete API.
|
214
|
+
|
215
|
+
## 9. Searching executables
|
216
|
+
|
217
|
+
To find executable path **TTY** uses [tty-which](https://github.com/peter-murach/tty-which#ttywhich) component.
|
218
|
+
|
219
|
+
For instance, to find out if `less` utility is actually supported by the system do:
|
190
220
|
|
191
221
|
```ruby
|
192
|
-
|
222
|
+
TTY::Which.which('less') # => '/usr/bin/less'
|
193
223
|
```
|
194
224
|
|
195
|
-
|
225
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-which) for complete API.
|
226
|
+
|
227
|
+
## 10. Prompting for input
|
196
228
|
|
197
229
|
Main responsibility is to interact with the prompt and provide convenience methods.
|
198
230
|
|
@@ -291,16 +323,9 @@ shell.suggest('sta', ['stage', 'stash', 'commit', 'branch'])
|
|
291
323
|
stash
|
292
324
|
```
|
293
325
|
|
294
|
-
## 8 System
|
295
|
-
|
296
|
-
```ruby
|
297
|
-
TTY::System.unix? # check if unix platform
|
298
|
-
TTY::System.windows? # check if windows platform
|
299
326
|
TTY::System.which(cmd) # full path to executable if found, nil otherwise
|
300
327
|
TTY::System.exists?(cmd) # check if command is available
|
301
328
|
TTY::System.editor # provides access to system editor
|
302
|
-
```
|
303
|
-
|
304
329
|
To set preferred editor you can either use shell environment variables such as `EDITOR` and `VISUAL` or set the command(s) manually like so
|
305
330
|
|
306
331
|
```ruby
|
data/lib/tty.rb
CHANGED
@@ -3,10 +3,13 @@
|
|
3
3
|
require 'equatable'
|
4
4
|
require 'pastel'
|
5
5
|
require 'necromancer'
|
6
|
+
require 'tty-pager'
|
7
|
+
require 'tty-platform'
|
8
|
+
require 'tty-progressbar'
|
6
9
|
require 'tty-screen'
|
7
10
|
require 'tty-spinner'
|
8
|
-
require 'tty-progressbar'
|
9
11
|
require 'tty-table'
|
12
|
+
require 'tty-which'
|
10
13
|
|
11
14
|
require 'tty/version'
|
12
15
|
|
@@ -37,11 +40,7 @@ require 'tty/shell/response'
|
|
37
40
|
require 'tty/terminal/echo'
|
38
41
|
require 'tty/terminal/raw'
|
39
42
|
require 'tty/terminal/home'
|
40
|
-
require 'tty/terminal/pager'
|
41
|
-
require 'tty/terminal/pager/basic'
|
42
|
-
require 'tty/terminal/pager/system'
|
43
43
|
|
44
|
-
require 'tty/system/which'
|
45
44
|
require 'tty/system/editor'
|
46
45
|
|
47
46
|
module TTY
|
data/lib/tty/system.rb
CHANGED
@@ -1,55 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'rbconfig'
|
4
|
-
|
5
3
|
module TTY
|
6
4
|
class System
|
7
|
-
# Check if windows platform.
|
8
|
-
#
|
9
|
-
# @return [Boolean]
|
10
|
-
#
|
11
|
-
# @api public
|
12
|
-
def self.windows?
|
13
|
-
match_os?(/msdos|mswin|djgpp|mingw|windows/i)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Check if unix platform
|
17
|
-
#
|
18
|
-
# @return [Boolean]
|
19
|
-
#
|
20
|
-
# @api public
|
21
|
-
def self.unix?
|
22
|
-
match_os?(/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Check if platform matches given systems
|
26
|
-
#
|
27
|
-
# @return [Boolean]
|
28
|
-
#
|
29
|
-
# @api public
|
30
|
-
def self.match_os?(matcher)
|
31
|
-
!!(RbConfig::CONFIG['host_os'] =~ matcher)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Find an executable in the PATH
|
35
|
-
#
|
36
|
-
# @see TTY::System::Which
|
37
|
-
#
|
38
|
-
# @api public
|
39
|
-
def self.which(command)
|
40
|
-
Which.new(command).which
|
41
|
-
end
|
42
|
-
|
43
|
-
# Check if command is available
|
44
|
-
#
|
45
|
-
# @param [String] name
|
46
|
-
# the command name
|
47
|
-
#
|
48
|
-
# @api public
|
49
|
-
def self.exists?(name)
|
50
|
-
!!which(name)
|
51
|
-
end
|
52
|
-
|
53
5
|
# Proxy to editor object
|
54
6
|
#
|
55
7
|
# @return [TTY::System::Editor]
|
data/lib/tty/terminal.rb
CHANGED
@@ -9,13 +9,6 @@ module TTY
|
|
9
9
|
# @api public
|
10
10
|
attr_reader :color
|
11
11
|
|
12
|
-
# Output pager
|
13
|
-
#
|
14
|
-
# @return [TTY::Terminal::Pager]
|
15
|
-
#
|
16
|
-
# @api public
|
17
|
-
attr_reader :pager
|
18
|
-
|
19
12
|
# Initialize a Terminal
|
20
13
|
#
|
21
14
|
# @api public
|
@@ -23,7 +16,6 @@ module TTY
|
|
23
16
|
@color = Pastel.new
|
24
17
|
@echo = TTY::Terminal::Echo.new
|
25
18
|
@raw = TTY::Terminal::Raw.new
|
26
|
-
@pager = TTY::Terminal::Pager
|
27
19
|
@home = Home.new
|
28
20
|
end
|
29
21
|
|
@@ -81,15 +73,5 @@ module TTY
|
|
81
73
|
def home
|
82
74
|
@home.home
|
83
75
|
end
|
84
|
-
|
85
|
-
# Run text through a dynamically chosen pager
|
86
|
-
#
|
87
|
-
# @param [String] text
|
88
|
-
# the text to page
|
89
|
-
#
|
90
|
-
# @api public
|
91
|
-
def page(text)
|
92
|
-
@pager.page(text)
|
93
|
-
end
|
94
76
|
end # Terminal
|
95
77
|
end # TTY
|
data/lib/tty/terminal/echo.rb
CHANGED
@@ -8,14 +8,14 @@ module TTY
|
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
def on
|
11
|
-
%x{stty echo} if TTY::
|
11
|
+
%x{stty echo} if TTY::Platform.unix?
|
12
12
|
end
|
13
13
|
|
14
14
|
# Turn echo off
|
15
15
|
#
|
16
16
|
# @api public
|
17
17
|
def off
|
18
|
-
%x{stty -echo} if TTY::
|
18
|
+
%x{stty -echo} if TTY::Platform.unix?
|
19
19
|
end
|
20
20
|
|
21
21
|
# Wrap code block inside echo
|
data/lib/tty/terminal/raw.rb
CHANGED
@@ -8,14 +8,14 @@ module TTY
|
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
def on
|
11
|
-
%x{stty raw} if TTY::
|
11
|
+
%x{stty raw} if TTY::Platform.unix?
|
12
12
|
end
|
13
13
|
|
14
14
|
# Turn raw mode off
|
15
15
|
#
|
16
16
|
# @api public
|
17
17
|
def off
|
18
|
-
%x{stty -raw} if TTY::
|
18
|
+
%x{stty -raw} if TTY::Platform.unix?
|
19
19
|
end
|
20
20
|
|
21
21
|
# Wrap code block inside raw mode
|
data/lib/tty/version.rb
CHANGED
data/tty.gemspec
CHANGED
@@ -17,10 +17,13 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency 'tty-
|
21
|
-
gem.add_dependency 'tty-
|
22
|
-
gem.add_dependency 'tty-
|
20
|
+
gem.add_dependency 'tty-pager', '~> 0.2.0'
|
21
|
+
gem.add_dependency 'tty-platform', '~> 0.1.0'
|
22
|
+
gem.add_dependency 'tty-progressbar', '~> 0.6.0'
|
23
|
+
gem.add_dependency 'tty-screen', '~> 0.2.0'
|
23
24
|
gem.add_dependency 'tty-spinner', '~> 0.1.0'
|
25
|
+
gem.add_dependency 'tty-table', '~> 0.3.0'
|
26
|
+
gem.add_dependency 'tty-which', '~> 0.1.0'
|
24
27
|
gem.add_dependency 'equatable', '~> 0.5.0'
|
25
28
|
gem.add_dependency 'necromancer', '~> 0.3.0'
|
26
29
|
gem.add_dependency 'pastel', '~> 0.4.0'
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty
|
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: 2015-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: tty-
|
14
|
+
name: tty-pager
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
@@ -24,22 +24,50 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tty-platform
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: tty-progressbar
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
47
|
+
version: 0.6.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
54
|
+
version: 0.6.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: tty-screen
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-spinner
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - ~>
|
@@ -53,7 +81,21 @@ dependencies:
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: 0.1.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: tty-
|
84
|
+
name: tty-table
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-which
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - ~>
|
@@ -162,13 +204,9 @@ files:
|
|
162
204
|
- lib/tty/support/utils.rb
|
163
205
|
- lib/tty/system.rb
|
164
206
|
- lib/tty/system/editor.rb
|
165
|
-
- lib/tty/system/which.rb
|
166
207
|
- lib/tty/terminal.rb
|
167
208
|
- lib/tty/terminal/echo.rb
|
168
209
|
- lib/tty/terminal/home.rb
|
169
|
-
- lib/tty/terminal/pager.rb
|
170
|
-
- lib/tty/terminal/pager/basic.rb
|
171
|
-
- lib/tty/terminal/pager/system.rb
|
172
210
|
- lib/tty/terminal/raw.rb
|
173
211
|
- lib/tty/vector.rb
|
174
212
|
- lib/tty/version.rb
|
@@ -221,19 +259,9 @@ files:
|
|
221
259
|
- spec/tty/system/editor/executables_spec.rb
|
222
260
|
- spec/tty/system/editor/invoke_spec.rb
|
223
261
|
- spec/tty/system/editor/open_spec.rb
|
224
|
-
- spec/tty/system/platform_spec.rb
|
225
|
-
- spec/tty/system/which/which_spec.rb
|
226
|
-
- spec/tty/system/which_spec.rb
|
227
262
|
- spec/tty/terminal/color_spec.rb
|
228
263
|
- spec/tty/terminal/echo_spec.rb
|
229
264
|
- spec/tty/terminal/home_spec.rb
|
230
|
-
- spec/tty/terminal/page_spec.rb
|
231
|
-
- spec/tty/terminal/pager/available_spec.rb
|
232
|
-
- spec/tty/terminal/pager/basic/page_spec.rb
|
233
|
-
- spec/tty/terminal/pager/command_spec.rb
|
234
|
-
- spec/tty/terminal/pager/executables_spec.rb
|
235
|
-
- spec/tty/terminal/pager/page_spec.rb
|
236
|
-
- spec/tty/terminal/pager/system/page_spec.rb
|
237
265
|
- spec/tty/tty_spec.rb
|
238
266
|
- spec/tty/vector/new_spec.rb
|
239
267
|
- tasks/console.rake
|
@@ -319,19 +347,9 @@ test_files:
|
|
319
347
|
- spec/tty/system/editor/executables_spec.rb
|
320
348
|
- spec/tty/system/editor/invoke_spec.rb
|
321
349
|
- spec/tty/system/editor/open_spec.rb
|
322
|
-
- spec/tty/system/platform_spec.rb
|
323
|
-
- spec/tty/system/which/which_spec.rb
|
324
|
-
- spec/tty/system/which_spec.rb
|
325
350
|
- spec/tty/terminal/color_spec.rb
|
326
351
|
- spec/tty/terminal/echo_spec.rb
|
327
352
|
- spec/tty/terminal/home_spec.rb
|
328
|
-
- spec/tty/terminal/page_spec.rb
|
329
|
-
- spec/tty/terminal/pager/available_spec.rb
|
330
|
-
- spec/tty/terminal/pager/basic/page_spec.rb
|
331
|
-
- spec/tty/terminal/pager/command_spec.rb
|
332
|
-
- spec/tty/terminal/pager/executables_spec.rb
|
333
|
-
- spec/tty/terminal/pager/page_spec.rb
|
334
|
-
- spec/tty/terminal/pager/system/page_spec.rb
|
335
353
|
- spec/tty/tty_spec.rb
|
336
354
|
- spec/tty/vector/new_spec.rb
|
337
355
|
has_rdoc:
|
data/lib/tty/system/which.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module TTY
|
4
|
-
class System
|
5
|
-
# A class responsible for finding an executable in the PATH
|
6
|
-
class Which
|
7
|
-
# The command to find
|
8
|
-
attr_reader :command
|
9
|
-
|
10
|
-
# Initialize a Which
|
11
|
-
#
|
12
|
-
# @param [String] command
|
13
|
-
# the command to find
|
14
|
-
#
|
15
|
-
# @api public
|
16
|
-
def initialize(command)
|
17
|
-
@command = command
|
18
|
-
end
|
19
|
-
|
20
|
-
# Find an executable in the PATH
|
21
|
-
#
|
22
|
-
# @param [String] command
|
23
|
-
# the command to search in the PATH
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# which("ruby") # => /usr/local/bin/ruby
|
27
|
-
#
|
28
|
-
# @return [String]
|
29
|
-
# the full path to executable if found, `nil` otherwise
|
30
|
-
#
|
31
|
-
# @api public
|
32
|
-
def which
|
33
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
34
|
-
default_system_path.each do |path|
|
35
|
-
exts.each do |ext|
|
36
|
-
exec = File.join("#{path}", "#{command}#{ext}")
|
37
|
-
return exec if File.executable? exec
|
38
|
-
end
|
39
|
-
end
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
# Find default system paths
|
44
|
-
#
|
45
|
-
# @api private
|
46
|
-
def default_system_path
|
47
|
-
ENV['PATH'].split(File::PATH_SEPARATOR)
|
48
|
-
end
|
49
|
-
end # Which
|
50
|
-
end # System
|
51
|
-
end # TTY
|
data/lib/tty/terminal/pager.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module TTY
|
4
|
-
class Terminal
|
5
|
-
# A class responsible for paging text inside terminal
|
6
|
-
class Pager
|
7
|
-
|
8
|
-
attr_accessor :enabled
|
9
|
-
|
10
|
-
attr_reader :text
|
11
|
-
|
12
|
-
@command = nil
|
13
|
-
|
14
|
-
# Initialize a Pager
|
15
|
-
#
|
16
|
-
# @param [String] text
|
17
|
-
# the text to page
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
def initialize(text = nil)
|
21
|
-
@text = text
|
22
|
-
@enabled = true
|
23
|
-
end
|
24
|
-
|
25
|
-
# Check if pager is enabled
|
26
|
-
#
|
27
|
-
# @return [Boolean]
|
28
|
-
#
|
29
|
-
# @api public
|
30
|
-
def enabled?
|
31
|
-
!!@enabled
|
32
|
-
end
|
33
|
-
|
34
|
-
# List possible executables for output paging
|
35
|
-
#
|
36
|
-
# @return [Array[String]]
|
37
|
-
#
|
38
|
-
# @api private
|
39
|
-
def self.executables
|
40
|
-
[ENV['GIT_PAGER'], `git config --get-all core.pager`.split.first,
|
41
|
-
ENV['PAGER'], 'less -isr', 'more', 'cat', 'pager']
|
42
|
-
end
|
43
|
-
|
44
|
-
# Find first available system command for paging
|
45
|
-
#
|
46
|
-
# @param [Array[String]] commands
|
47
|
-
#
|
48
|
-
# @return [String]
|
49
|
-
#
|
50
|
-
# @api public
|
51
|
-
def self.available(*commands)
|
52
|
-
commands = commands.empty? ? executables : commands
|
53
|
-
commands.compact.uniq.find { |cmd| System.exists?(cmd) }
|
54
|
-
end
|
55
|
-
|
56
|
-
# Check if paging command exists
|
57
|
-
#
|
58
|
-
# @api private
|
59
|
-
def self.available?
|
60
|
-
!!available
|
61
|
-
end
|
62
|
-
|
63
|
-
# Finds command to execute pager from shell commands
|
64
|
-
# unless configured is provided.
|
65
|
-
#
|
66
|
-
# @param [Array[String]] commands
|
67
|
-
#
|
68
|
-
# @return [String]
|
69
|
-
#
|
70
|
-
# @api private
|
71
|
-
def self.command(*commands)
|
72
|
-
@command = if @command && commands.empty?
|
73
|
-
@command
|
74
|
-
else
|
75
|
-
available(*commands)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# Pages output using configured pager
|
80
|
-
#
|
81
|
-
# @param [String] text
|
82
|
-
# the text to page
|
83
|
-
#
|
84
|
-
# @api public
|
85
|
-
def self.page(text)
|
86
|
-
return unless TTY.shell.tty?
|
87
|
-
|
88
|
-
if System.unix? && available?
|
89
|
-
SystemPager.new(text).page
|
90
|
-
else
|
91
|
-
BasicPager.new(text).page
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end # Pager
|
95
|
-
end # Terminal
|
96
|
-
end # TTY
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module TTY
|
4
|
-
class Terminal
|
5
|
-
# A class responsible for paging text
|
6
|
-
class BasicPager < Pager
|
7
|
-
PROMPT_HEIGHT = 3
|
8
|
-
|
9
|
-
PAGE_BREAK = '--- Press enter/return to continue (or q to quit) ---'
|
10
|
-
|
11
|
-
# Use ruby to page output text
|
12
|
-
#
|
13
|
-
# @api public
|
14
|
-
def page
|
15
|
-
text_lines = text.lines.to_a
|
16
|
-
|
17
|
-
text_lines.each_slice(page_size) do |chunk|
|
18
|
-
TTY.shell.say chunk.join
|
19
|
-
break if chunk.size < page_size
|
20
|
-
break if !continue?(text_lines)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
# Check whether to progress with paging
|
27
|
-
#
|
28
|
-
# @param [Array[String]] text_lines
|
29
|
-
#
|
30
|
-
# @return [Boolean]
|
31
|
-
#
|
32
|
-
# @api private
|
33
|
-
def continue?(text_lines)
|
34
|
-
if text_lines.size > page_size
|
35
|
-
question = TTY.shell.ask "\n#{PAGE_BREAK}"
|
36
|
-
return false if question.read_string[/q/i]
|
37
|
-
end
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
# Determine current page size
|
42
|
-
#
|
43
|
-
# @api private
|
44
|
-
def page_size
|
45
|
-
@page_size ||= TTY.terminal.height - PROMPT_HEIGHT
|
46
|
-
end
|
47
|
-
end # BasicPager
|
48
|
-
end # Terminal
|
49
|
-
end # TTY
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module TTY
|
4
|
-
class Terminal
|
5
|
-
# A class responsible for paging text
|
6
|
-
class SystemPager < Pager
|
7
|
-
# Use system command to page output text
|
8
|
-
#
|
9
|
-
# @api public
|
10
|
-
def page
|
11
|
-
read_io, write_io = IO.pipe
|
12
|
-
|
13
|
-
if Kernel.fork
|
14
|
-
# parent process
|
15
|
-
TTY.shell.input.reopen(read_io)
|
16
|
-
read_io.close
|
17
|
-
write_io.close
|
18
|
-
|
19
|
-
# Wait until we have input before we start the pager
|
20
|
-
Kernel.select [TTY.shell.stdin]
|
21
|
-
|
22
|
-
begin
|
23
|
-
Kernel.exec(Pager.command)
|
24
|
-
rescue
|
25
|
-
Kernel.exec '/bin/sh', '-c', command
|
26
|
-
end
|
27
|
-
else
|
28
|
-
# child process
|
29
|
-
write_io.write(text)
|
30
|
-
write_io.close
|
31
|
-
read_io.close
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end # SystemPager
|
35
|
-
end # Terminal
|
36
|
-
end # TTY
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::System, '#platform' do
|
6
|
-
subject(:system) { described_class }
|
7
|
-
|
8
|
-
it { is_expected.to respond_to(:windows?) }
|
9
|
-
|
10
|
-
it { is_expected.to respond_to(:unix?) }
|
11
|
-
|
12
|
-
it { is_expected.to respond_to(:which) }
|
13
|
-
|
14
|
-
it { is_expected.to respond_to(:exists?) }
|
15
|
-
|
16
|
-
it { is_expected.to respond_to(:editor) }
|
17
|
-
|
18
|
-
context 'windows?' do
|
19
|
-
it 'is on windows' do
|
20
|
-
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('windows')
|
21
|
-
expect(system.windows?).to eq(true)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'is on windows ignoring case' do
|
25
|
-
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('Windows')
|
26
|
-
expect(system.windows?).to eq(true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'is not on windows' do
|
30
|
-
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('unknown')
|
31
|
-
expect(system.windows?).to eq(false)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'unix?' do
|
36
|
-
it 'checks if unix' do
|
37
|
-
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('darwin')
|
38
|
-
expect(system.unix?).to eq(true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'checks if unix' do
|
42
|
-
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('unknown')
|
43
|
-
expect(system.unix?).to eq(false)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::System::Which, '#which' do
|
6
|
-
let(:path) { "/usr/local/bin:/usr/local/git/bin" }
|
7
|
-
let(:extension) { '.bat' }
|
8
|
-
|
9
|
-
subject { described_class.new(command) }
|
10
|
-
|
11
|
-
context 'without extension' do
|
12
|
-
let(:command) { 'ruby' }
|
13
|
-
|
14
|
-
before {
|
15
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil)
|
16
|
-
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
17
|
-
}
|
18
|
-
|
19
|
-
it 'finds command' do
|
20
|
-
allow(File).to receive(:executable?) { true }
|
21
|
-
expect(subject.which).to eql "/usr/local/bin/ruby"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "doesn't find command" do
|
25
|
-
allow(File).to receive(:executable?) { false }
|
26
|
-
expect(subject.which).to be_nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with extension' do
|
31
|
-
let(:command) { 'ruby' }
|
32
|
-
|
33
|
-
before {
|
34
|
-
allow(ENV).to receive(:[]).with('PATHEXT').and_return(extension)
|
35
|
-
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
36
|
-
}
|
37
|
-
|
38
|
-
it 'finds command' do
|
39
|
-
allow(File).to receive(:executable?) { true }
|
40
|
-
expect(subject.which).to eql "/usr/local/bin/ruby.bat"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "doesn't find command" do
|
44
|
-
allow(File).to receive(:executable?) { false }
|
45
|
-
expect(subject.which).to be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::System, '#which' do
|
6
|
-
let(:command) { 'ruby' }
|
7
|
-
let(:which) { double(:which, :which => command) }
|
8
|
-
|
9
|
-
subject(:system) { described_class }
|
10
|
-
|
11
|
-
it 'seeks system command' do
|
12
|
-
allow(TTY::System::Which).to receive(:new).with(command).and_return(which)
|
13
|
-
expect(system.which(command)).to eql(command)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal, '#page' do
|
6
|
-
let(:text) { "a\n"}
|
7
|
-
|
8
|
-
subject(:terminal) { described_class.new }
|
9
|
-
|
10
|
-
it 'invokes pager page method' do
|
11
|
-
expect(terminal.pager).to receive(:page).with(text)
|
12
|
-
terminal.page(text)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Pager, '#available' do
|
6
|
-
let(:execs) { ['less', 'more'] }
|
7
|
-
let(:system) { TTY::System }
|
8
|
-
let(:command) { 'less' }
|
9
|
-
|
10
|
-
subject(:pager) { described_class }
|
11
|
-
|
12
|
-
before { allow(subject).to receive(:executables).and_return(execs) }
|
13
|
-
|
14
|
-
context 'when command exists' do
|
15
|
-
before {
|
16
|
-
allow(system).to receive(:exists?).with('less').and_return(true)
|
17
|
-
allow(system).to receive(:exists?).with('more').and_return(false)
|
18
|
-
}
|
19
|
-
|
20
|
-
it 'finds single command' do
|
21
|
-
expect(pager.available).to eql('less')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when no command exists' do
|
26
|
-
before { allow(system).to receive(:exists?).and_return(false) }
|
27
|
-
|
28
|
-
it "doesn't find command" do
|
29
|
-
expect(pager.available).to be_nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when custom command' do
|
34
|
-
before { allow(system).to receive(:exists?).with(command).and_return(true) }
|
35
|
-
|
36
|
-
it "takes precedence over other commands" do
|
37
|
-
expect(subject.available(command)).to eql(command)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::BasicPager, '#simple' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:shell) { TTY::Shell.new(input, output) }
|
9
|
-
let(:terminal) { TTY.terminal }
|
10
|
-
let(:object) { described_class }
|
11
|
-
|
12
|
-
subject(:pager) { object.new(text) }
|
13
|
-
|
14
|
-
before {
|
15
|
-
allow(TTY).to receive(:shell).and_return(shell)
|
16
|
-
allow(terminal).to receive(:height).and_return(10)
|
17
|
-
}
|
18
|
-
|
19
|
-
context 'when no text' do
|
20
|
-
let(:text) { "" }
|
21
|
-
|
22
|
-
it "doesn't page text" do
|
23
|
-
pager.page
|
24
|
-
expect(output.string).to eql(text)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when text fits on screen' do
|
29
|
-
let(:text) { "a\n" }
|
30
|
-
|
31
|
-
it "doesn't page text not long enough" do
|
32
|
-
pager.page
|
33
|
-
expect(output.string).to eql(text)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when text doesn't fit on screen" do
|
38
|
-
let(:text) { "a\na\na\na\na\na\na\na\na\na\n" }
|
39
|
-
|
40
|
-
it "continues paging when enter is pressed" do
|
41
|
-
input << '\n'
|
42
|
-
input.rewind
|
43
|
-
pager.page
|
44
|
-
expect(output.string).to eql("a\na\na\na\na\na\na\n\n#{object::PAGE_BREAK}\na\na\na\n")
|
45
|
-
end
|
46
|
-
|
47
|
-
it "stops paging when q is pressed" do
|
48
|
-
input << 'q\n'
|
49
|
-
input.rewind
|
50
|
-
pager.page
|
51
|
-
expect(output.string).to eql("a\na\na\na\na\na\na\n\n#{object::PAGE_BREAK}\n")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Pager, '#command' do
|
6
|
-
let(:pager) { 'vim' }
|
7
|
-
|
8
|
-
subject { described_class }
|
9
|
-
|
10
|
-
context 'when custom command' do
|
11
|
-
it 'searches available commands' do
|
12
|
-
expect(subject).to receive(:available).with(pager)
|
13
|
-
subject.command(pager)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Pager, '#executables' do
|
6
|
-
let(:object) { described_class }
|
7
|
-
|
8
|
-
subject { object.executables }
|
9
|
-
|
10
|
-
it { is_expected.to be_an(Array) }
|
11
|
-
|
12
|
-
it { is_expected.to include('less -isr') }
|
13
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Pager, '#page' do
|
6
|
-
let(:text) { "a\n" }
|
7
|
-
let(:shell) { TTY.shell }
|
8
|
-
let(:system) { TTY::System }
|
9
|
-
let(:pager) { double(:pager, :page => nil) }
|
10
|
-
let(:basic_pager) { TTY::Terminal::BasicPager }
|
11
|
-
let(:system_pager) { TTY::Terminal::SystemPager }
|
12
|
-
|
13
|
-
subject { described_class }
|
14
|
-
|
15
|
-
before { allow(shell).to receive(:tty?).and_return(true) }
|
16
|
-
|
17
|
-
context 'when not tty' do
|
18
|
-
before { allow(shell).to receive(:tty?).and_return(false) }
|
19
|
-
|
20
|
-
it "doesn't page" do
|
21
|
-
expect(subject.page(text)).to eql(nil)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when not unix' do
|
26
|
-
before { allow(system).to receive(:unix?).and_return(false) }
|
27
|
-
|
28
|
-
it 'pages with simple pager' do
|
29
|
-
expect(basic_pager).to receive(:new).with(text).and_return(pager)
|
30
|
-
subject.page(text)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when unix and available' do
|
35
|
-
before {
|
36
|
-
allow(system).to receive(:unix?).and_return(true)
|
37
|
-
allow(subject).to receive(:available?).and_return(true)
|
38
|
-
}
|
39
|
-
|
40
|
-
it 'pages with system pager' do
|
41
|
-
expect(system_pager).to receive(:new).with(text).and_return(pager)
|
42
|
-
subject.page(text)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::SystemPager, '#simple' do
|
6
|
-
let(:input) { StringIO.new }
|
7
|
-
let(:output) { StringIO.new }
|
8
|
-
let(:shell) { TTY::Shell.new(input, output) }
|
9
|
-
let(:terminal) { TTY.terminal }
|
10
|
-
let(:object) { described_class }
|
11
|
-
|
12
|
-
subject(:pager) { object.new(text) }
|
13
|
-
|
14
|
-
before {
|
15
|
-
allow(TTY).to receive(:shell).and_return(shell)
|
16
|
-
allow(IO).to receive(:pipe).and_return([input, output])
|
17
|
-
allow(Kernel).to receive(:fork) { true }
|
18
|
-
}
|
19
|
-
|
20
|
-
context 'when text fits on screen' do
|
21
|
-
let(:text) { "a\na\na\na\na\na\na\na\na\na\n" }
|
22
|
-
|
23
|
-
it "doesn't page text not long enough" do
|
24
|
-
expect(Kernel).to receive(:exec)
|
25
|
-
expect(Kernel).to receive(:select)
|
26
|
-
pager.page
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|