tty-pager 0.9.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2c1947e24364321ab077aa4a9426654ecba831c
4
- data.tar.gz: 86a316d617688d3e644802748ab991bd599eb8fd
2
+ SHA256:
3
+ metadata.gz: adbdf02c80e21f7b2c2fc7723af3a00d268c8a57bffd321e8ed5126e6b7cc120
4
+ data.tar.gz: 4ff28aeef0acff9e54343e498e890bb2ffde576b771b4172326ef3dcdda67fc3
5
5
  SHA512:
6
- metadata.gz: 5d4a40162a5d370d66f70f6967e21b088ca09e7fc4b213d9b190e169b1111cf8cf2d37d0db421ad39372629f1213814ad6b6ceb524ee06a3c360bb6bee2865a2
7
- data.tar.gz: 9258e5ecba6052965b5336a932e38140c6bcb64d8ceffb8220ca73d131f331ab1752ac6a3b82ee29a6fece8cbc960036dd1501abc955563bbeb84999e92d66a7
6
+ metadata.gz: 5614a278d417950a369489d6480203150da012ea19c1d2e1c564ac989d3f3c32074ce5f7ae61952536ec758f7602512415b63027f891e73b4d96151a6e9b02e4
7
+ data.tar.gz: ec0c2b331343284877e199e1f1672776e967f58f58b1b608ae73653f84905c6214b30990bb928b3f912f1d345dfce42dcfcc5947fd1fdd4f13330705844accaa
@@ -1,5 +1,67 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.13.0] - 2020-05-30
4
+
5
+ ### Added
6
+ * Add support for streaming by Andrew Radev(@AndrewRadev)
7
+ * Add SystemPager integration tests by Andrew Radev(@AndrewRadev)
8
+
9
+ ### Changed
10
+ * Change Pager structure and extract TTY::Pager::Abstract for the null, basic and
11
+ system pagers
12
+ * Change BasicPager paging prompt to return only formatted prompt text and
13
+ account for terminal height
14
+ * Change BasicPager to quit with a single keystroke
15
+ * Change BasicPager internals to increase readability
16
+ * Change SystemPager#command_exist? to search path
17
+ * Change tests structure for ease of maintenance by Andrew Radev(@AndrewRadev)
18
+ * Change gemspec to add metadata, remove test artefacts and dev dependencies
19
+ * Update strings & tty-screen dependencies
20
+ * Remove tty-which dependency
21
+
22
+ ### Fixed
23
+ * Fix SystemPager to run command test silently via Open3 and thus work on JRuby
24
+
25
+ ## [v0.12.1] - 2019-03-16
26
+
27
+ ### Fixed
28
+ * Fix exception when use tty-pager with tty-file by @tiev
29
+
30
+ ## [v0.12.0] - 2018-12-09
31
+
32
+ ### Added
33
+ * Add SystemPager#run_command for running pager command silently and capturing output
34
+
35
+ ### Changed
36
+ * Change SystemPager#new to allow specifying more than one custom command
37
+ * Change SystemPager#page to check if pager command can be run with flags before paging content
38
+ * Change to update tty-screen and tty-which dependencies
39
+
40
+ ### Fixed
41
+ * Fix SystemPager to page content with ANSI codes
42
+
43
+ ## [v0.11.0] - 2018-01-11
44
+
45
+ ### Added
46
+ * Add `pg` and `most` to executables lookup
47
+
48
+ ### Changed
49
+ * Change verse to strings dependency
50
+ * Change SystemPager to make all class methods public
51
+ * Change SystemPager#available to #find_executable
52
+ * Change SystemPager#available? to #exec_available
53
+ * Change Pager#find_available to #select_pager and make class method
54
+
55
+ ### Fixed
56
+ * Fix Pager throwing exception if git is not installed by Katelyn Schiesser(@slowbro)
57
+
58
+ ## [v0.10.0] - 2017-10-29
59
+
60
+ ### Changed
61
+ * Change tty-screen dependency version
62
+ * Change gemspec to require Ruby >= 2.0.0
63
+ * Remove encoding comments
64
+
3
65
  ## [v0.9.0] - 2017-08-18
4
66
 
5
67
  ### Changed
@@ -62,13 +124,22 @@
62
124
  ### Changed
63
125
  * Change SystemPager to correctly paginate inside a process.
64
126
 
65
- [v0.9.0]: https://github.com/peter-murach/tty-prompt/compare/v0.8.0...v0.9.0
66
- [v0.8.0]: https://github.com/peter-murach/tty-prompt/compare/v0.7.1...v0.8.0
67
- [v0.7.1]: https://github.com/peter-murach/tty-prompt/compare/v0.7.0...v0.7.1
68
- [v0.7.0]: https://github.com/peter-murach/tty-prompt/compare/v0.6.0...v0.7.0
69
- [v0.6.0]: https://github.com/peter-murach/tty-prompt/compare/v0.5.0...v0.6.0
70
- [v0.5.0]: https://github.com/peter-murach/tty-prompt/compare/v0.4.0...v0.5.0
71
- [v0.4.0]: https://github.com/peter-murach/tty-prompt/compare/v0.3.0...v0.4.0
72
- [v0.3.0]: https://github.com/peter-murach/tty-prompt/compare/v0.2.0...v0.3.0
73
- [v0.2.0]: https://github.com/peter-murach/tty-prompt/compare/v0.1.0...v0.2.0
74
- [v0.1.0]: https://github.com/peter-murach/tty-prompt/compare/v0.1.0
127
+ ### [v0.1.0] - 2015-05-31
128
+
129
+ * Initial release
130
+
131
+ [v0.13.0]: https://github.com/piotrmurach/tty-pager/compare/v0.12.1...v0.13.0
132
+ [v0.12.1]: https://github.com/piotrmurach/tty-pager/compare/v0.12.0...v0.12.1
133
+ [v0.12.0]: https://github.com/piotrmurach/tty-pager/compare/v0.11.0...v0.12.0
134
+ [v0.11.0]: https://github.com/piotrmurach/tty-pager/compare/v0.10.0...v0.11.0
135
+ [v0.10.0]: https://github.com/piotrmurach/tty-pager/compare/v0.9.0...v0.10.0
136
+ [v0.9.0]: https://github.com/piotrmurach/tty-pager/compare/v0.8.0...v0.9.0
137
+ [v0.8.0]: https://github.com/piotrmurach/tty-pager/compare/v0.7.1...v0.8.0
138
+ [v0.7.1]: https://github.com/piotrmurach/tty-pager/compare/v0.7.0...v0.7.1
139
+ [v0.7.0]: https://github.com/piotrmurach/tty-pager/compare/v0.6.0...v0.7.0
140
+ [v0.6.0]: https://github.com/piotrmurach/tty-pager/compare/v0.5.0...v0.6.0
141
+ [v0.5.0]: https://github.com/piotrmurach/tty-pager/compare/v0.4.0...v0.5.0
142
+ [v0.4.0]: https://github.com/piotrmurach/tty-pager/compare/v0.3.0...v0.4.0
143
+ [v0.3.0]: https://github.com/piotrmurach/tty-pager/compare/v0.2.0...v0.3.0
144
+ [v0.2.0]: https://github.com/piotrmurach/tty-pager/compare/v0.1.0...v0.2.0
145
+ [v0.1.0]: https://github.com/piotrmurach/tty-pager/compare/v0.1.0
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
- [![Code Climate](https://codeclimate.com/github/piotrmurach/tty-pager/badges/gpa.svg)][codeclimate]
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
- > Terminal output paging in a cross-platform way supporting all major ruby interpreters.
22
+ > A cross-platform terminal pager that works on all major Ruby interpreters.
18
23
 
19
- **TTY::Pager** provides independent terminal output paging component for [TTY](https://github.com/piotrmurach/tty) toolkit.
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** on initialization will choose the best available pager out of `SystemPager`, `BasicPager` or `NullPager`. If paging is disabled then a `NullPager` is used, which either returns text as is or simply prints it out to stdout on tty devices. Otherwise a check is performed to find paging command to page text with `SystemPager`. However, if no paging command is found, a `BasicPager` is used which is a pure Ruby implementation that is guaranteed to work with any ruby interpreter and any platform.
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
- In order to let **TTY::Pager** pick the best paging mechanism automatically do:
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 perform actual content pagination invoke `page` method with the content to paginate as the argument:
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
- If you want to use specific pager you can do so by invoking it directly
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. Interface
125
+ ## 2. API
61
126
 
62
- ### :enabled
127
+ ### 2.1 new
63
128
 
64
- If you want to disable the pager pass the `:enabled` option set to `false`:
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 enabled: false
142
+ pager = TTY::Pager.new(enabled: false)
68
143
  ```
69
144
 
70
- ### :width
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
- The `BasicPager` allows to wrap content at given width:
149
+ To force `TTY::Pager` to always use a specific paging tool(s), use the `:command` option:
73
150
 
74
151
  ```ruby
75
- pager = TTY::Pager::BasicPager.new width: 80
152
+ TTY::Pager.new(command: "less -R")
76
153
  ```
77
154
 
78
- ### :prompt
155
+ The `:command` also accepts an array of pagers to use:
79
156
 
80
- For the `BasicPager` you can pass a `:prompt` option to change the page break text:
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
- prompt = -> (page_num) { output.puts "Page -#{page_num}- Press enter to continue" }
84
- pager = TTY::Pager::BasicPager.new prompt: prompt
182
+ pager = TTY::Pager::BasicPager.new(width: 80)
85
183
  ```
86
184
 
87
- ### :command
185
+ #### 2.1.4 :prompt
88
186
 
89
- You can force `SystemPager` to always use a specific paging tool by passing the `:command` option:
187
+ To change the `BasicPager` page break prompt display, use the `:prompt` option:
90
188
 
91
189
  ```ruby
92
- TTY::Pager.new command; 'less -R'
93
- TTY::Pager::SystemPager.new command: 'less -R'
190
+ prompt = -> (page) { "Page -#{page_num}- Press enter to continue" }
191
+ pager = TTY::Pager.new(prompt: prompt)
94
192
  ```
95
193
 
96
- ### PAGER
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
- By default the `SystemPager` will check the `PAGER` environment variable, if not set it will try one of the `less`, `more`, `cat`, `pager`. Therefore, if you wish to set your prefered pager you can either set up your shell like so:
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
- or set `PAGER` in Ruby script:
319
+ Or set `PAGER` in Ruby script:
106
320
 
107
321
  ```ruby
108
- ENV['PAGER']='less'
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-2017 Piotr Murach. See LICENSE for further details.
341
+ Copyright (c) 2015 Piotr Murach. See LICENSE for further details.