tty-pager 0.10.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +84 -11
- data/LICENSE.txt +1 -1
- data/README.md +247 -29
- data/lib/tty-pager.rb +1 -1
- data/lib/tty/pager.rb +86 -85
- data/lib/tty/pager/abstract.rb +138 -0
- data/lib/tty/pager/basic.rb +198 -55
- data/lib/tty/pager/null.rb +22 -3
- data/lib/tty/pager/system.rb +192 -72
- data/lib/tty/pager/version.rb +4 -2
- metadata +30 -88
- data/.gitignore +0 -22
- data/.rspec +0 -3
- data/.travis.yml +0 -24
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -14
- data/Rakefile +0 -8
- data/appveyor.yml +0 -21
- data/examples/basic_pager.rb +0 -7
- data/examples/system_pager.rb +0 -9
- data/examples/temp.txt +0 -49
- data/spec/spec_helper.rb +0 -43
- data/spec/unit/basic/page_spec.rb +0 -140
- data/spec/unit/null/page_spec.rb +0 -21
- data/spec/unit/page_spec.rb +0 -38
- data/spec/unit/system/available_spec.rb +0 -48
- data/spec/unit/system/command_exists_spec.rb +0 -13
- data/spec/unit/system/new_spec.rb +0 -8
- data/spec/unit/system/page_spec.rb +0 -19
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-pager.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd9cf11b53f54bc92e50fb26df8d79da6939036e31d535dfcaed127c6cce1670
|
4
|
+
data.tar.gz: 268dd645947a90ac2e25a2df885ea4809c030eaa3b8ce3cc470f576e43b6e870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb2e07da311cb829f9a99355424621e2394eb0d79511988c3277374ceeaaf6b59a78fa876c2b6d04338a8bc2ff992e62c9be319113df92b4c23ecec42e8aa892
|
7
|
+
data.tar.gz: e762220845ff96c7b9214db592f00a2e9757befd5490092886337e788b8d69bfbbd439e7711b23aec68bcb27e3aae3ab4ede2b83da53c9f31ec3271bdf0ec394
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,69 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.14.0] - 2020-10-15
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change to update strings dependency
|
7
|
+
* Change to allow the pager to be specified via an absolute path (@WilliamMcCumstie)
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
* Fix name resolution with TTY::File
|
11
|
+
|
12
|
+
## [v0.13.0] - 2020-05-30
|
13
|
+
|
14
|
+
### Added
|
15
|
+
* Add support for streaming by Andrew Radev(@AndrewRadev)
|
16
|
+
* Add SystemPager integration tests by Andrew Radev(@AndrewRadev)
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
* Change Pager structure and extract TTY::Pager::Abstract for the null, basic and
|
20
|
+
system pagers
|
21
|
+
* Change BasicPager paging prompt to return only formatted prompt text and
|
22
|
+
account for terminal height
|
23
|
+
* Change BasicPager to quit with a single keystroke
|
24
|
+
* Change BasicPager internals to increase readability
|
25
|
+
* Change SystemPager#command_exist? to search path
|
26
|
+
* Change tests structure for ease of maintenance by Andrew Radev(@AndrewRadev)
|
27
|
+
* Change gemspec to add metadata, remove test artefacts and dev dependencies
|
28
|
+
* Update strings & tty-screen dependencies
|
29
|
+
* Remove tty-which dependency
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
* Fix SystemPager to run command test silently via Open3 and thus work on JRuby
|
33
|
+
|
34
|
+
## [v0.12.1] - 2019-03-16
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
* Fix exception when use tty-pager with tty-file by @tiev
|
38
|
+
|
39
|
+
## [v0.12.0] - 2018-12-09
|
40
|
+
|
41
|
+
### Added
|
42
|
+
* Add SystemPager#run_command for running pager command silently and capturing output
|
43
|
+
|
44
|
+
### Changed
|
45
|
+
* Change SystemPager#new to allow specifying more than one custom command
|
46
|
+
* Change SystemPager#page to check if pager command can be run with flags before paging content
|
47
|
+
* Change to update tty-screen and tty-which dependencies
|
48
|
+
|
49
|
+
### Fixed
|
50
|
+
* Fix SystemPager to page content with ANSI codes
|
51
|
+
|
52
|
+
## [v0.11.0] - 2018-01-11
|
53
|
+
|
54
|
+
### Added
|
55
|
+
* Add `pg` and `most` to executables lookup
|
56
|
+
|
57
|
+
### Changed
|
58
|
+
* Change verse to strings dependency
|
59
|
+
* Change SystemPager to make all class methods public
|
60
|
+
* Change SystemPager#available to #find_executable
|
61
|
+
* Change SystemPager#available? to #exec_available
|
62
|
+
* Change Pager#find_available to #select_pager and make class method
|
63
|
+
|
64
|
+
### Fixed
|
65
|
+
* Fix Pager throwing exception if git is not installed by Katelyn Schiesser(@slowbro)
|
66
|
+
|
3
67
|
## [v0.10.0] - 2017-10-29
|
4
68
|
|
5
69
|
### Changed
|
@@ -69,14 +133,23 @@
|
|
69
133
|
### Changed
|
70
134
|
* Change SystemPager to correctly paginate inside a process.
|
71
135
|
|
72
|
-
[v0.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
[v0.
|
77
|
-
[v0.
|
78
|
-
[v0.
|
79
|
-
[v0.
|
80
|
-
[v0.
|
81
|
-
[v0.
|
82
|
-
[v0.
|
136
|
+
### [v0.1.0] - 2015-05-31
|
137
|
+
|
138
|
+
* Initial release
|
139
|
+
|
140
|
+
[v0.14.0]: https://github.com/piotrmurach/tty-pager/compare/v0.13.0...v0.14.0
|
141
|
+
[v0.13.0]: https://github.com/piotrmurach/tty-pager/compare/v0.12.1...v0.13.0
|
142
|
+
[v0.12.1]: https://github.com/piotrmurach/tty-pager/compare/v0.12.0...v0.12.1
|
143
|
+
[v0.12.0]: https://github.com/piotrmurach/tty-pager/compare/v0.11.0...v0.12.0
|
144
|
+
[v0.11.0]: https://github.com/piotrmurach/tty-pager/compare/v0.10.0...v0.11.0
|
145
|
+
[v0.10.0]: https://github.com/piotrmurach/tty-pager/compare/v0.9.0...v0.10.0
|
146
|
+
[v0.9.0]: https://github.com/piotrmurach/tty-pager/compare/v0.8.0...v0.9.0
|
147
|
+
[v0.8.0]: https://github.com/piotrmurach/tty-pager/compare/v0.7.1...v0.8.0
|
148
|
+
[v0.7.1]: https://github.com/piotrmurach/tty-pager/compare/v0.7.0...v0.7.1
|
149
|
+
[v0.7.0]: https://github.com/piotrmurach/tty-pager/compare/v0.6.0...v0.7.0
|
150
|
+
[v0.6.0]: https://github.com/piotrmurach/tty-pager/compare/v0.5.0...v0.6.0
|
151
|
+
[v0.5.0]: https://github.com/piotrmurach/tty-pager/compare/v0.4.0...v0.5.0
|
152
|
+
[v0.4.0]: https://github.com/piotrmurach/tty-pager/compare/v0.3.0...v0.4.0
|
153
|
+
[v0.3.0]: https://github.com/piotrmurach/tty-pager/compare/v0.2.0...v0.3.0
|
154
|
+
[v0.2.0]: https://github.com/piotrmurach/tty-pager/compare/v0.1.0...v0.2.0
|
155
|
+
[v0.1.0]: https://github.com/piotrmurach/tty-pager/compare/v0.1.0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="tty logo" /></a>
|
3
|
+
</div>
|
4
|
+
|
1
5
|
# TTY::Pager [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
|
6
|
+
|
2
7
|
[![Gem Version](https://badge.fury.io/rb/tty-pager.svg)][gem]
|
3
8
|
[![Build Status](https://secure.travis-ci.org/piotrmurach/tty-pager.svg?branch=master)][travis]
|
4
9
|
[![Build status](https://ci.appveyor.com/api/projects/status/3auc1vi3mk5puqai?svg=true)][appveyor]
|
5
|
-
[![
|
10
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/636da0d02231b7f3e50f/maintainability)][codeclimate]
|
6
11
|
[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-pager/badge.svg)][coverage]
|
7
12
|
[![Inline docs](http://inch-ci.org/github/piotrmurach/tty-pager.svg?branch=master)][inchpages]
|
8
13
|
|
@@ -10,13 +15,13 @@
|
|
10
15
|
[gem]: http://badge.fury.io/rb/tty-pager
|
11
16
|
[travis]: http://travis-ci.org/piotrmurach/tty-pager
|
12
17
|
[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-pager
|
13
|
-
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-pager
|
18
|
+
[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-pager/maintainability
|
14
19
|
[coverage]: https://coveralls.io/github/piotrmurach/tty-pager
|
15
20
|
[inchpages]: http://inch-ci.org/github/piotrmurach/tty-pager
|
16
21
|
|
17
|
-
>
|
22
|
+
> A cross-platform terminal pager that works on all major Ruby interpreters.
|
18
23
|
|
19
|
-
**TTY::Pager** provides independent terminal
|
24
|
+
**TTY::Pager** provides independent terminal pager component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
20
25
|
|
21
26
|
## Installation
|
22
27
|
|
@@ -35,77 +40,286 @@ Or install it yourself as:
|
|
35
40
|
|
36
41
|
## Overview
|
37
42
|
|
38
|
-
The **TTY::Pager**
|
43
|
+
The **TTY::Pager** will automatically choose the best available pager on a user's system. Failing to do so, it will fallback on a pure Ruby version that is guaranteed to work with any Ruby interpreter and on any platform.
|
44
|
+
|
45
|
+
## Contents
|
46
|
+
|
47
|
+
* [1. Usage](#1-usage)
|
48
|
+
* [2. API](#2-api)
|
49
|
+
* [2.1 new](#21-new)
|
50
|
+
* [2.1.1 :enabled](#211-enabled)
|
51
|
+
* [2.1.2 :command](#212-command)
|
52
|
+
* [2.1.3 :width](#213-width)
|
53
|
+
* [2.1.4 :prompt](#214-prompt)
|
54
|
+
* [2.2 page](#22-page)
|
55
|
+
* [2.3 write](#23-write)
|
56
|
+
* [2.4 try_write](#24-try_write)
|
57
|
+
* [2.5 puts](#25-puts)
|
58
|
+
* [2.6 close](#26-close)
|
59
|
+
* [2.7 ENV](#27-env)
|
39
60
|
|
40
61
|
## 1. Usage
|
41
62
|
|
42
|
-
|
63
|
+
The **TTY::Pager** will pick the best paging mechanism available on your system when initialized:
|
43
64
|
|
44
65
|
```ruby
|
45
66
|
pager = TTY::Pager.new
|
46
67
|
```
|
47
68
|
|
48
|
-
Then to
|
69
|
+
Then to start paginating text call the `page` method with the content as the first argument:
|
49
70
|
|
50
71
|
```ruby
|
51
72
|
pager.page("Very long text...")
|
52
73
|
```
|
53
74
|
|
54
|
-
|
75
|
+
This will launch a pager in the background and wait until the user is done.
|
76
|
+
|
77
|
+
Alternatively, you can pass the `:path` keyword to specify a file path:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
pager.page(path: "/path/to/filename.txt")
|
81
|
+
```
|
82
|
+
|
83
|
+
If instead you'd like to paginate a long-running operation, you could use the block form of the pager:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
TTY::Pager.page do |pager|
|
87
|
+
File.open("file_with_lots_of_lines.txt", "r").each_line do |line|
|
88
|
+
# do some work with the line
|
89
|
+
|
90
|
+
pager.write(line) # send it to the pager
|
91
|
+
end
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
After block finishes, the pager is automatically closed.
|
96
|
+
|
97
|
+
For more control, you can translate the block form into separate `write` and `close` calls:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
begin
|
101
|
+
pager = TTY::Pager.new
|
102
|
+
|
103
|
+
File.open("file_with_lots_of_lines.txt", "r").each_line do |line|
|
104
|
+
# do some work with the line
|
105
|
+
|
106
|
+
pager.write(line) # send it to the pager
|
107
|
+
end
|
108
|
+
rescue TTY::Pager::PagerClosed
|
109
|
+
# the user closed the paginating tool
|
110
|
+
ensure
|
111
|
+
pager.close
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
If you want to use a specific pager you can do so by invoking it directly:
|
55
116
|
|
56
117
|
```ruby
|
57
118
|
pager = TTY::Pager::BasicPager.new
|
119
|
+
# or
|
120
|
+
pager = TTY::Pager::SystemPager.new
|
121
|
+
# or
|
122
|
+
pager = TTY::Pager::NullPager.new
|
58
123
|
```
|
59
124
|
|
60
|
-
## 2.
|
125
|
+
## 2. API
|
61
126
|
|
62
|
-
###
|
127
|
+
### 2.1 new
|
63
128
|
|
64
|
-
|
129
|
+
The `TTY::Pager` can be configured during initialization for terminal width, type of prompt when basic pager is invoked, and the pagination command to run.
|
130
|
+
|
131
|
+
For example, to disable a pager in CI you could do:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
pager = TTY::Pager.new(enabled: false)
|
135
|
+
````
|
136
|
+
|
137
|
+
#### 2.1.1 :enabled
|
138
|
+
|
139
|
+
If you want to disable the paging use the `:enabled` option set to `false`:
|
65
140
|
|
66
141
|
```ruby
|
67
|
-
pager = TTY::Pager.new
|
142
|
+
pager = TTY::Pager.new(enabled: false)
|
68
143
|
```
|
69
144
|
|
70
|
-
|
145
|
+
This will directly print all the content to the standard output. If the output isn't a tty device, the pager will return the content directly to the caller.
|
146
|
+
|
147
|
+
#### 2.1.2 :command
|
71
148
|
|
72
|
-
|
149
|
+
To force `TTY::Pager` to always use a specific paging tool(s), use the `:command` option:
|
73
150
|
|
74
151
|
```ruby
|
75
|
-
|
152
|
+
TTY::Pager.new(command: "less -R")
|
76
153
|
```
|
77
154
|
|
78
|
-
|
155
|
+
The `:command` also accepts an array of pagers to use:
|
79
156
|
|
80
|
-
|
157
|
+
```ruby
|
158
|
+
pager = TTY::Pager.new(command: ["less -r", "more -r"])
|
159
|
+
```
|
160
|
+
|
161
|
+
If the provided pager command or commands don't exist on user's system, the pager will fallback automatically on a basic Ruby implementation.
|
162
|
+
|
163
|
+
To skip automatic detection of pager and always use a system pager do:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
TTY::Pager::SystemPager.new(command: "less -R")
|
167
|
+
```
|
168
|
+
|
169
|
+
#### 2.1.3 :width
|
170
|
+
|
171
|
+
Only the `BasicPager` allows you to wrap content at given terminal width:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
pager = TTY::Pager.new(width: 80)
|
175
|
+
```
|
176
|
+
|
177
|
+
This option doesn't affect the `SystemPager`.
|
178
|
+
|
179
|
+
To directly use `BasicPager` do:
|
81
180
|
|
82
181
|
```ruby
|
83
|
-
|
84
|
-
pager = TTY::Pager::BasicPager.new prompt: prompt
|
182
|
+
pager = TTY::Pager::BasicPager.new(width: 80)
|
85
183
|
```
|
86
184
|
|
87
|
-
|
185
|
+
#### 2.1.4 :prompt
|
88
186
|
|
89
|
-
|
187
|
+
To change the `BasicPager` page break prompt display, use the `:prompt` option:
|
90
188
|
|
91
189
|
```ruby
|
92
|
-
|
93
|
-
TTY::Pager
|
190
|
+
prompt = -> (page) { "Page -#{page_num}- Press enter to continue" }
|
191
|
+
pager = TTY::Pager.new(prompt: prompt)
|
94
192
|
```
|
95
193
|
|
96
|
-
###
|
194
|
+
### 2.2 page
|
195
|
+
|
196
|
+
To start paging use the `page` method. It can be invoked on an instance or a class.
|
197
|
+
|
198
|
+
The class-level `page` is a convenient shortcut. To page some text you only need to do:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
TTY::Pager.page("Some long text...")
|
202
|
+
````
|
203
|
+
|
204
|
+
You can also include extra initialization parameters. For example, if you prefer to use a specific command do this:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
TTY::Pager.page("Some long text...", command: "less -R")
|
208
|
+
````
|
209
|
+
|
210
|
+
The instance equivalent would be:
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
pager = TTY::Pager.new(command: "less -R")
|
214
|
+
pager.page("Some long text...")
|
215
|
+
````
|
97
216
|
|
98
|
-
|
217
|
+
Apart from text, you can page file content by passing the `:path` option:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
TTY::Pager.page(path: "/path/to/filename.txt")
|
221
|
+
````
|
222
|
+
|
223
|
+
The final way is to use the class-level `page` with a block. After the block is done, the pager is automatically closed. For example, to read a file line by line with additional processing you could do:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
TTY::Pager.page do |pager|
|
227
|
+
File.foreach("filename.txt") do |line|
|
228
|
+
# do some work with the line
|
229
|
+
|
230
|
+
pager.write(line) # write line to the pager
|
231
|
+
end
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
235
|
+
The instance equivalent of the block version would be:
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
pager = TTY::Pager.new
|
239
|
+
begin
|
240
|
+
File.foreach("filename.txt") do |line|
|
241
|
+
# do some work with the line
|
242
|
+
|
243
|
+
pager.write(line) # write line to the pager
|
244
|
+
end
|
245
|
+
rescue TTY::Pager::PagerClosed
|
246
|
+
ensure
|
247
|
+
pager.close
|
248
|
+
end
|
249
|
+
```
|
250
|
+
|
251
|
+
### 2.3 write
|
252
|
+
|
253
|
+
To stream content to the pager use the `write` method.
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
pager.write("Some text")
|
257
|
+
```
|
258
|
+
|
259
|
+
You can pass in any number of arguments:
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
pager.write("one", "two", "three")
|
263
|
+
```
|
264
|
+
|
265
|
+
### 2.4 try_write
|
266
|
+
|
267
|
+
To check if a write has been successful use `try_write`:
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
pager.try_write("Some text")
|
271
|
+
# => true
|
272
|
+
```
|
273
|
+
|
274
|
+
### 2.5 puts
|
275
|
+
|
276
|
+
To write a line of text and end it with a new line use `puts` call:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
pager.puts("Single line of content")
|
280
|
+
```
|
281
|
+
|
282
|
+
### 2.6 close
|
283
|
+
|
284
|
+
When you're done streaming content manually use `close` to finish paging.
|
285
|
+
|
286
|
+
All interactions with a pager can raise an exception for various reasons, so wrap your code using the following pattern:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
pager = TTY::Pager.new
|
290
|
+
|
291
|
+
begin
|
292
|
+
# ... perform pager writes
|
293
|
+
rescue TTY::Pager::PagerClosed
|
294
|
+
# the user closed the paginating tool
|
295
|
+
ensure
|
296
|
+
pager.close
|
297
|
+
end
|
298
|
+
```
|
299
|
+
|
300
|
+
Alternatively use the class-level `page` call with a block to automatically close the pager:
|
301
|
+
|
302
|
+
```ruby
|
303
|
+
TTY::Pager.page do |pager|
|
304
|
+
# ... perform pager writes
|
305
|
+
end
|
306
|
+
```
|
307
|
+
|
308
|
+
### 2.7 ENV
|
309
|
+
|
310
|
+
By default the `SystemPager` will check the `PAGER` environment variable. If the `PAGER` isn't set, the pager will try one of the searched commands like `less`, `more` or `pg`.
|
311
|
+
|
312
|
+
Therefore, if you wish to set your preferred pager you can either set up your shell like so:
|
99
313
|
|
100
314
|
```bash
|
101
|
-
PAGER=less
|
315
|
+
PAGER=less -R
|
102
316
|
export PAGER
|
103
317
|
```
|
104
318
|
|
105
|
-
|
319
|
+
Or set `PAGER` in Ruby script:
|
106
320
|
|
107
321
|
```ruby
|
108
|
-
ENV[
|
322
|
+
ENV["PAGER"]="less -R"
|
109
323
|
```
|
110
324
|
|
111
325
|
## Contributing
|
@@ -118,6 +332,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/piotrm
|
|
118
332
|
4. Push to the branch (`git push origin my-new-feature`)
|
119
333
|
5. Create a new Pull Request
|
120
334
|
|
335
|
+
## Code of Conduct
|
336
|
+
|
337
|
+
Everyone interacting in the TTY::Pager project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-pager/blob/master/CODE_OF_CONDUCT.md).
|
338
|
+
|
121
339
|
## Copyright
|
122
340
|
|
123
|
-
Copyright (c) 2015
|
341
|
+
Copyright (c) 2015 Piotr Murach. See LICENSE for further details.
|