tty-pager 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,5 +0,0 @@
1
- require_relative '../lib/tty-pager'
2
-
3
- pager = TTY::Pager::BasicPager.new(width: 80)
4
- file = File.join(File.dirname(__FILE__), 'temp.txt')
5
- pager.page(File.read(file))
@@ -1,7 +0,0 @@
1
- require 'tty-markdown'
2
- require_relative '../lib/tty-pager'
3
-
4
- pager = TTY::Pager.new
5
- file = File.join(__dir__, '../README.md')
6
- text = TTY::Markdown.parse_file(file)
7
- pager.page(text)
@@ -1,7 +0,0 @@
1
- require_relative '../lib/tty-pager'
2
-
3
- ENV['PAGER']='less'
4
-
5
- pager = TTY::Pager.new
6
- file = File.join(File.dirname(__FILE__), 'temp.txt')
7
- pager.page(File.read(file))
@@ -1,7 +0,0 @@
1
- require_relative '../lib/tty-pager'
2
-
3
- ENV['PAGER']='less'
4
-
5
- pager = TTY::Pager::SystemPager.new
6
- file = File.join(File.dirname(__FILE__), 'temp.txt')
7
- pager.page(File.read(file))
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty-pager'
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |expectations|
22
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
- end
24
-
25
- config.mock_with :rspec do |mocks|
26
- mocks.verify_partial_doubles = true
27
- end
28
-
29
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
30
- config.disable_monkey_patching!
31
-
32
- # This setting enables warnings. It's recommended, but in some cases may
33
- # be too noisy due to issues in dependencies.
34
- config.warnings = true
35
-
36
- if config.files_to_run.one?
37
- config.default_formatter = 'doc'
38
- end
39
-
40
- config.profile_examples = 2
41
-
42
- config.order = :random
43
-
44
- Kernel.srand config.seed
45
- end
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::BasicPager, '.page' do
4
- let(:input) { StringIO.new }
5
- let(:output) { StringIO.new }
6
-
7
- it "doesn't paginate empty string" do
8
- pager = described_class.new(output: output, input: input)
9
- pager.page("")
10
- expect(output.string).to eq("")
11
- end
12
-
13
- it "doesn't paginate text that fits on screen" do
14
- text = "I try all things, I achieve what I can.\n"
15
- pager = described_class.new(output: output, width: 100, height: 10)
16
- pager.page(text)
17
- expect(output.string).to eq(text)
18
- end
19
-
20
- it "breaks text exceeding terminal width" do
21
- text = "It is not down on any map; true places never are.\n"
22
- input << "\n"
23
- input.rewind
24
- pager = described_class.new(output: output, input: input,
25
- width: 10, height: 6)
26
- pager.page(text)
27
- expect(output.string).to eq([
28
- "It is not ",
29
- "down on ",
30
- "any map; ",
31
- "true ",
32
- "",
33
- "--- Page ",
34
- "-1- Press ",
35
- "e",
36
- "nter/retur",
37
- "n to ",
38
- "continue ",
39
- "(or q to ",
40
- "quit) ---",
41
- "places ",
42
- "never are.\n"
43
- ].join("\n"))
44
- end
45
-
46
- it "continues paging when enter is pressed" do
47
- text = []
48
- 10.times { text << "I try all things, I achieve what I can.\n"}
49
- input << "\n\n\n"
50
- input.rewind
51
- pager = described_class.new(output: output, input: input,
52
- width: 100, height: 5)
53
- pager.page(text.join)
54
- expect(output.string).to eq([
55
- "I try all things, I achieve what I can.",
56
- "I try all things, I achieve what I can.",
57
- "I try all things, I achieve what I can.",
58
- "",
59
- "--- Page -1- Press enter/return to continue (or q to quit) ---",
60
- "I try all things, I achieve what I can.",
61
- "I try all things, I achieve what I can.",
62
- "I try all things, I achieve what I can.",
63
- "",
64
- "--- Page -2- Press enter/return to continue (or q to quit) ---",
65
- "I try all things, I achieve what I can.",
66
- "I try all things, I achieve what I can.",
67
- "I try all things, I achieve what I can.",
68
- "",
69
- "--- Page -3- Press enter/return to continue (or q to quit) ---",
70
- "I try all things, I achieve what I can.\n"
71
- ].join("\n"))
72
- end
73
-
74
- it "stops paging when q is pressed" do
75
- text = []
76
- 10.times { text << "I try all things, I achieve what I can.\n"}
77
- input << "\nq\n"
78
- input.rewind
79
- pager = described_class.new(output: output, input: input,
80
- width: 100, height: 5)
81
- pager.page(text.join)
82
- expect(output.string).to eq([
83
- "I try all things, I achieve what I can.",
84
- "I try all things, I achieve what I can.",
85
- "I try all things, I achieve what I can.",
86
- "",
87
- "--- Page -1- Press enter/return to continue (or q to quit) ---",
88
- "I try all things, I achieve what I can.",
89
- "I try all things, I achieve what I can.",
90
- "I try all things, I achieve what I can.",
91
- "",
92
- "--- Page -2- Press enter/return to continue (or q to quit) ---\n",
93
- ].join("\n"))
94
- end
95
-
96
- it "allows to change paging prompt" do
97
- text = []
98
- 5.times { text << "I try all things, I achieve what I can.\n"}
99
- input << "\nq\n"
100
- input.rewind
101
- prompt = proc { |num| output.puts "Page -#{num}-" }
102
- pager = described_class.new(output: output, input: input,
103
- width: 100, height: 5, prompt: prompt)
104
- pager.page(text.join)
105
- expect(output.string).to eq([
106
- "I try all things, I achieve what I can.",
107
- "I try all things, I achieve what I can.",
108
- "I try all things, I achieve what I can.",
109
- "Page -1-",
110
- "I try all things, I achieve what I can.",
111
- "I try all things, I achieve what I can.\n",
112
- ].join("\n"))
113
- end
114
-
115
- it "preserves new lines when breaking" do
116
- text = "a\na\na\na\na\na\na\na\na\na"
117
- input << "\n\n\n"
118
- input.rewind
119
- pager = described_class.new(output: output, input: input,
120
- width: 80, height: 5)
121
- pager.page(text)
122
- expect(output.string).to eq([
123
- "a",
124
- "a",
125
- "a",
126
- "",
127
- "--- Page -1- Press enter/return to continue (or q to quit) ---",
128
- "a",
129
- "a",
130
- "a",
131
- "",
132
- "--- Page -2- Press enter/return to continue (or q to quit) ---",
133
- "a",
134
- "a",
135
- "a",
136
- "",
137
- "--- Page -3- Press enter/return to continue (or q to quit) ---",
138
- "a"
139
- ].join("\n"))
140
- end
141
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::NullPager, '.page' do
4
- let(:output) { StringIO.new }
5
-
6
- it "prints content to stdout when tty device" do
7
- allow(output).to receive(:tty?).and_return(true)
8
- pager = described_class.new(output: output)
9
- text = "I try all things, I achieve what I can.\n"
10
-
11
- pager.page(text)
12
-
13
- expect(output.string).to eq(text)
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
23
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager, '.page' do
4
- let(:output) { StringIO.new }
5
-
6
- it "selects null pager when disabled" do
7
- null_pager = spy(:null_pager)
8
- allow(TTY::Pager::NullPager).to receive(:new) { null_pager }
9
-
10
- pager = described_class.new(enabled: false)
11
- text = "I try all things, I achieve what I can.\n"
12
- pager.page(text)
13
-
14
- expect(TTY::Pager::NullPager).to have_received(:new)
15
- end
16
-
17
- it "selects BasicPager when no paging command is available" do
18
- basic_pager = spy(:basic_pager)
19
- allow(TTY::Pager::SystemPager).to receive(:exec_available?) { false }
20
- allow(TTY::Pager::BasicPager).to receive(:new) { basic_pager }
21
-
22
- pager = described_class.new
23
- text = "I try all things, I achieve what I can.\n"
24
- pager.page(text)
25
-
26
- expect(basic_pager).to have_received(:page).with(text)
27
- end
28
-
29
- it "selects SystemPager when paging command is available" do
30
- system_pager = spy(:system_pager)
31
- allow(TTY::Pager::SystemPager).to receive(:exec_available?) { true }
32
- allow(TTY::Pager::SystemPager).to receive(:new) { system_pager }
33
-
34
- pager = described_class.new
35
- text = "I try all things, I achieve what I can.\n"
36
- pager.page(text)
37
-
38
- expect(system_pager).to have_received(:page).with(text)
39
- end
40
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::SystemPager, '#command_exists?' do
4
- subject(:pager) { described_class }
5
-
6
- it "successfully checks command exists on the system" do
7
- allow(TTY::Which).to receive(:exist?).with('less').and_return('/usr/bin/less').and_return(true)
8
- expect(pager.command_exists?('less')).to eq(true)
9
- end
10
-
11
- it "fails to check command exists on the system" do
12
- allow(TTY::Which).to receive(:exist?).with('less').and_return(false)
13
- expect(pager.command_exists?('less')).to eq(false)
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::SystemPager do
4
- it "provides executable names" do
5
- allow(ENV).to receive(:[]).with('GIT_PAGER').and_return(nil)
6
- allow(ENV).to receive(:[]).with('PAGER').and_return(nil)
7
- allow(described_class).to receive(:command_exists?).with('git').and_return(false)
8
-
9
- expect(described_class.executables).to eq(['less -r', 'more -r', 'most', 'cat', 'pager', 'pg'])
10
- end
11
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::SystemPager, '#find_executable' do
4
- let(:execs) { ['less', 'more'] }
5
-
6
- subject(:pager) { described_class }
7
-
8
- it 'finds available command' do
9
- allow(pager).to receive(:executables).and_return(execs)
10
- allow(pager).to receive(:command_exists?).with('less') { true }
11
- allow(pager).to receive(:command_exists?).with('more') { false }
12
- expect(pager.find_executable).to eql('less')
13
- end
14
-
15
- it "doesn't find command" do
16
- allow(pager).to receive(:executables).and_return(execs)
17
- allow(pager).to receive(:command_exists?) { false }
18
- expect(pager.find_executable).to be_nil
19
- end
20
-
21
- it "takes precedence over other commands" do
22
- allow(pager).to receive(:command_exists?).with('more') { true }
23
- expect(pager.find_executable('more')).to eql('more')
24
- end
25
-
26
- it "allows to query for available command" do
27
- allow(pager).to receive(:find_executable).with('less') { true }
28
- expect(pager.exec_available?('less')).to eq(true)
29
- end
30
-
31
- context "when given nil, blank, and whitespace commands" do
32
- let(:execs) { [nil, "", " ", "less"] }
33
-
34
- it "does not error" do
35
- allow(pager).to receive(:executables).and_return(execs)
36
- allow(pager).to receive(:command_exists?).with('less') { true }
37
- expect(pager.find_executable).to eql('less')
38
- end
39
- end
40
-
41
- context "when given a multi-word executable" do
42
- let(:execs) { ["diff-so-fancy | less --tabs=4 -RFX"] }
43
-
44
- it "finds the command" do
45
- allow(pager).to receive(:executables).and_return(execs)
46
- allow(pager).to receive(:command_exists?).with("diff-so-fancy") { true }
47
- expect(pager.find_executable).to eql(execs.first)
48
- end
49
- end
50
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::SystemPager, '#new' do
4
- it "raises error if system paging is not supported" do
5
- allow(TTY::Pager::SystemPager).to receive(:find_executable).and_return(nil)
6
-
7
- expect {
8
- TTY::Pager::SystemPager.new
9
- }.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.")
10
- end
11
-
12
- it "accepts multiple commands" do
13
- allow(TTY::Pager::SystemPager)
14
- .to receive(:find_executable).and_return('more -r')
15
-
16
- TTY::Pager::SystemPager.new(command: ['less -r', 'more -r'])
17
-
18
- expect(TTY::Pager::SystemPager)
19
- .to have_received(:find_executable).with('less -r', 'more -r')
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Pager::SystemPager, '.page' do
4
- it "executes the pager command in a subprocess" do
5
- text = "I try all things, I achieve what I can.\n"
6
- allow(TTY::Pager::SystemPager).to receive(:exec_available?).and_return(true)
7
- output = double(:output, :tty? => true)
8
- pager = described_class.new(output: output)
9
- write_io = spy
10
- pid = 12345
11
-
12
- allow(pager).to receive(:open).and_return(write_io)
13
- allow(write_io).to receive(:pid).and_return(pid)
14
- status = double(:status, :success? => true)
15
- allow(Process).to receive(:waitpid2).with(pid, any_args).and_return([1, status])
16
-
17
- expect(pager.page(text)).to eq(true)
18
- expect(write_io).to have_received(:write).with(text)
19
- expect(write_io).to have_received(:close)
20
- end
21
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require_relative '../lib/tty-pager'
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task :c => :console
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end