tty-pager 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/appveyor.yml +2 -0
- data/lib/tty/pager.rb +4 -11
- data/lib/tty/pager/basic.rb +1 -1
- data/lib/tty/pager/null.rb +4 -1
- data/lib/tty/pager/system.rb +13 -42
- data/lib/tty/pager/version.rb +2 -2
- data/spec/unit/null/page_spec.rb +12 -1
- data/spec/unit/page_spec.rb +4 -6
- data/spec/unit/system/new_spec.rb +2 -2
- data/spec/unit/system/page_spec.rb +9 -27
- 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: e2c1947e24364321ab077aa4a9426654ecba831c
|
4
|
+
data.tar.gz: 86a316d617688d3e644802748ab991bd599eb8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d4a40162a5d370d66f70f6967e21b088ca09e7fc4b213d9b190e169b1111cf8cf2d37d0db421ad39372629f1213814ad6b6ceb524ee06a3c360bb6bee2865a2
|
7
|
+
data.tar.gz: 9258e5ecba6052965b5336a932e38140c6bcb64d8ceffb8220ca73d131f331ab1752ac6a3b82ee29a6fece8cbc960036dd1501abc955563bbeb84999e92d66a7
|
data/.travis.yml
CHANGED
@@ -12,14 +12,12 @@ rvm:
|
|
12
12
|
- 2.3.3
|
13
13
|
- 2.4.1
|
14
14
|
- ruby-head
|
15
|
-
- jruby-
|
15
|
+
- jruby-9.1.5.0
|
16
16
|
- jruby-head
|
17
|
-
- rbx-3
|
18
17
|
matrix:
|
19
18
|
allow_failures:
|
20
19
|
- rvm: ruby-head
|
21
20
|
- rvm: jruby-head
|
22
|
-
- rvm: rbx-3
|
23
21
|
fast_finish: true
|
24
22
|
branches:
|
25
23
|
only: master
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.9.0] - 2017-08-18
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change SystemPager to stop using fork, instead execute pager in subprocess
|
7
|
+
and make it portable across platforms including Windows
|
8
|
+
* Change SystemPager to work on jruby
|
9
|
+
* Change NullPager to only print to stdout on tty device
|
10
|
+
* Change Pager to select SystemPager when paging command exists
|
11
|
+
* Remove jruby? checks from pager selection
|
12
|
+
|
3
13
|
## [v0.8.0] - 2017-07-14
|
4
14
|
|
5
15
|
### Added
|
@@ -52,6 +62,9 @@
|
|
52
62
|
### Changed
|
53
63
|
* Change SystemPager to correctly paginate inside a process.
|
54
64
|
|
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
|
55
68
|
[v0.7.0]: https://github.com/peter-murach/tty-prompt/compare/v0.6.0...v0.7.0
|
56
69
|
[v0.6.0]: https://github.com/peter-murach/tty-prompt/compare/v0.5.0...v0.6.0
|
57
70
|
[v0.5.0]: https://github.com/peter-murach/tty-prompt/compare/v0.4.0...v0.5.0
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
## Overview
|
37
37
|
|
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
|
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.
|
39
39
|
|
40
40
|
## 1. Usage
|
41
41
|
|
data/appveyor.yml
CHANGED
data/lib/tty/pager.rb
CHANGED
@@ -84,26 +84,19 @@ module TTY
|
|
84
84
|
#
|
85
85
|
# If the user disabled paging then a NullPager is returned,
|
86
86
|
# otherwise a check is performed to find native system
|
87
|
-
#
|
88
|
-
# if no system
|
89
|
-
# is pure Ruby implementation.
|
87
|
+
# command to perform pagination with SystemPager. Finally,
|
88
|
+
# if no system command is found, a BasicPager is used which
|
89
|
+
# is a pure Ruby implementation known to work on any platform.
|
90
90
|
#
|
91
91
|
# @api private
|
92
92
|
def find_available(options)
|
93
93
|
if !enabled?
|
94
94
|
NullPager.new
|
95
|
-
elsif
|
95
|
+
elsif SystemPager.available?
|
96
96
|
SystemPager.new(options)
|
97
97
|
else
|
98
98
|
BasicPager.new(options)
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
102
|
-
# Check if running on jruby
|
103
|
-
#
|
104
|
-
# @api private
|
105
|
-
def self.jruby?
|
106
|
-
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
107
|
-
end
|
108
101
|
end # Pager
|
109
102
|
end # TTY
|
data/lib/tty/pager/basic.rb
CHANGED
data/lib/tty/pager/null.rb
CHANGED
data/lib/tty/pager/system.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'tty-which'
|
4
5
|
|
@@ -19,9 +20,11 @@ module TTY
|
|
19
20
|
def initialize(options = {})
|
20
21
|
super
|
21
22
|
@pager_command = options[:command]
|
22
|
-
unless self.class.
|
23
|
+
unless self.class.available?
|
23
24
|
raise TTY::Pager::Error, "#{self.class.name} cannot be used on your" \
|
24
|
-
" system
|
25
|
+
" system due to lack of appropriate pager" \
|
26
|
+
" executable. Install `less` like pager or" \
|
27
|
+
" try using `BasicPager` instead." \
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
@@ -60,28 +63,6 @@ module TTY
|
|
60
63
|
!available(*commands).nil?
|
61
64
|
end
|
62
65
|
|
63
|
-
# Check if fork is supported
|
64
|
-
#
|
65
|
-
# @return [Boolean]
|
66
|
-
#
|
67
|
-
# @api public
|
68
|
-
def self.fork?
|
69
|
-
pid = fork {}
|
70
|
-
exit unless pid
|
71
|
-
true
|
72
|
-
rescue NotImplementedError
|
73
|
-
false
|
74
|
-
end
|
75
|
-
|
76
|
-
# Check if fork & comman exist
|
77
|
-
#
|
78
|
-
# @return [Boolean]
|
79
|
-
#
|
80
|
-
# @api public
|
81
|
-
def self.can?
|
82
|
-
self.fork? && self.available?
|
83
|
-
end
|
84
|
-
|
85
66
|
# Use system command to page output text
|
86
67
|
#
|
87
68
|
# @example
|
@@ -95,29 +76,19 @@ module TTY
|
|
95
76
|
#
|
96
77
|
# @api public
|
97
78
|
def page(text, &callback)
|
98
|
-
|
79
|
+
return text unless output.tty?
|
99
80
|
|
100
|
-
|
101
|
-
|
102
|
-
input.reopen(read_io)
|
103
|
-
read_io.close
|
81
|
+
write_io = open("|#{pager_command}", 'w')
|
82
|
+
pid = write_io.pid
|
104
83
|
|
105
|
-
# Wait until we have input before we start the pager
|
106
|
-
IO.select [input]
|
107
|
-
|
108
|
-
begin
|
109
|
-
exec(pager_command)
|
110
|
-
rescue SystemCallError
|
111
|
-
exit 1
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
read_io.close
|
116
84
|
write_io.write(text)
|
117
85
|
write_io.close
|
118
86
|
|
119
|
-
_, status = Process.waitpid2(pid)
|
87
|
+
_, status = Process.waitpid2(pid, Process::WNOHANG)
|
120
88
|
status.success?
|
89
|
+
rescue Errno::ECHILD
|
90
|
+
# on jruby 9x waiting on pid raises
|
91
|
+
true
|
121
92
|
end
|
122
93
|
|
123
94
|
private
|
data/lib/tty/pager/version.rb
CHANGED
data/spec/unit/null/page_spec.rb
CHANGED
@@ -3,10 +3,21 @@
|
|
3
3
|
RSpec.describe TTY::Pager::NullPager, '.page' do
|
4
4
|
let(:output) { StringIO.new }
|
5
5
|
|
6
|
-
it "
|
6
|
+
it "prints content to stdout when tty device" do
|
7
|
+
allow(output).to receive(:tty?).and_return(true)
|
7
8
|
pager = described_class.new(output: output)
|
8
9
|
text = "I try all things, I achieve what I can.\n"
|
10
|
+
|
9
11
|
pager.page(text)
|
12
|
+
|
10
13
|
expect(output.string).to eq(text)
|
11
14
|
end
|
15
|
+
|
16
|
+
it "returns text when non-tty device" do
|
17
|
+
pager = described_class.new(output: output)
|
18
|
+
text = "I try all things, I achieve what I can.\n"
|
19
|
+
|
20
|
+
expect(pager.page(text)).to eq(text)
|
21
|
+
expect(output.string).to eq('')
|
22
|
+
end
|
12
23
|
end
|
data/spec/unit/page_spec.rb
CHANGED
@@ -14,10 +14,9 @@ RSpec.describe TTY::Pager, '.page' do
|
|
14
14
|
expect(TTY::Pager::NullPager).to have_received(:new)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "selects
|
17
|
+
it "selects BasicPager when no paging command is available" do
|
18
18
|
basic_pager = spy(:basic_pager)
|
19
|
-
allow(
|
20
|
-
allow(TTY::Pager::SystemPager).to receive(:can?) { false }
|
19
|
+
allow(TTY::Pager::SystemPager).to receive(:available?) { false }
|
21
20
|
allow(TTY::Pager::BasicPager).to receive(:new) { basic_pager }
|
22
21
|
|
23
22
|
pager = described_class.new
|
@@ -27,10 +26,9 @@ RSpec.describe TTY::Pager, '.page' do
|
|
27
26
|
expect(basic_pager).to have_received(:page).with(text)
|
28
27
|
end
|
29
28
|
|
30
|
-
it "selects
|
29
|
+
it "selects SystemPager when paging command is available" do
|
31
30
|
system_pager = spy(:system_pager)
|
32
|
-
allow(
|
33
|
-
allow(TTY::Pager::SystemPager).to receive(:can?) { true }
|
31
|
+
allow(TTY::Pager::SystemPager).to receive(:available?) { true }
|
34
32
|
allow(TTY::Pager::SystemPager).to receive(:new) { system_pager }
|
35
33
|
|
36
34
|
pager = described_class.new
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
RSpec.describe TTY::Pager::SystemPager, '#new' do
|
4
4
|
it "raises error if system paging is not supported" do
|
5
|
-
allow(TTY::Pager::SystemPager).to receive(:
|
5
|
+
allow(TTY::Pager::SystemPager).to receive(:available?).and_return(false)
|
6
6
|
expect {
|
7
7
|
TTY::Pager::SystemPager.new
|
8
|
-
}.to raise_error(TTY::Pager::Error, "TTY::Pager::SystemPager cannot be used on your system.
|
8
|
+
}.to raise_error(TTY::Pager::Error, "TTY::Pager::SystemPager cannot be used on your system due to lack of appropriate pager executable. Install `less` like pager or try using `BasicPager` instead.")
|
9
9
|
end
|
10
10
|
end
|
@@ -1,39 +1,21 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
RSpec.describe TTY::Pager::SystemPager, '.page' do
|
4
|
-
let(:input) { StringIO.new }
|
5
|
-
let(:output) { StringIO.new }
|
6
|
-
|
7
4
|
it "executes the pager command in a subprocess" do
|
8
5
|
text = "I try all things, I achieve what I can.\n"
|
9
|
-
allow(TTY::Pager::SystemPager).to receive(:
|
10
|
-
|
11
|
-
|
6
|
+
allow(TTY::Pager::SystemPager).to receive(:available?).and_return(true)
|
7
|
+
output = double(:output, :tty? => true)
|
8
|
+
pager = described_class.new(output: output)
|
12
9
|
write_io = spy
|
10
|
+
pid = 12345
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
yield if block_given?
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
allow(IO).to receive(:pipe).and_return([read_io, write_io])
|
21
|
-
|
22
|
-
allow(pager).to receive(:fork) do |&block|
|
23
|
-
allow(input).to receive(:reopen)
|
24
|
-
allow(IO).to receive(:select)
|
25
|
-
allow(pager).to receive(:pager_command).and_return('less')
|
26
|
-
allow(pager).to receive(:exec)
|
27
|
-
block.call
|
28
|
-
end.and_return(12345)
|
29
|
-
|
12
|
+
allow(pager).to receive(:open).and_return(write_io)
|
13
|
+
allow(write_io).to receive(:pid).and_return(pid)
|
30
14
|
status = double(:status, :success? => true)
|
31
|
-
allow(Process).to receive(:waitpid2).with(
|
15
|
+
allow(Process).to receive(:waitpid2).with(pid, any_args).and_return([1, status])
|
32
16
|
|
33
17
|
expect(pager.page(text)).to eq(true)
|
34
|
-
|
35
|
-
expect(
|
36
|
-
expect(pager).to have_received(:exec).with('less')
|
37
|
-
expect(output.read).to eq('')
|
18
|
+
expect(write_io).to have_received(:write).with(text)
|
19
|
+
expect(write_io).to have_received(:close)
|
38
20
|
end
|
39
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-pager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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: 2017-
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-screen
|