Commit 6c64eeb6 authored by Muhammed Yavuz Nuzumlali's avatar Muhammed Yavuz Nuzumlali

Merge pull request #4560 from CocoaPods/yavuz/imp/UIWithPager

[User Interface] add method to pipe outputs to a pager
parents 2128c44a abce6b74
...@@ -368,6 +368,21 @@ module Pod ...@@ -368,6 +368,21 @@ module Pod
warnings << { :message => message, :actions => actions, :verbose_only => verbose_only } warnings << { :message => message, :actions => actions, :verbose_only => verbose_only }
end end
# Pipes all output inside given block to a pager.
#
# @yield Code block in which inputs to {#puts} and {#print} methods will be printed to the piper.
#
def with_pager
prev_handler = Signal.trap('INT', 'IGNORE')
IO.popen((ENV['PAGER'] || 'less -R'), 'w') do |io|
UI.output_io = io
yield
end
ensure
Signal.trap('INT', prev_handler)
UI.output_io = nil
end
private private
# @!group Helpers # @!group Helpers
......
...@@ -26,6 +26,18 @@ module Pod ...@@ -26,6 +26,18 @@ module Pod
# TODO # TODO
end end
describe '#with_pager' do
it 'sets output_io' do
fd = IO.sysopen('/dev/null', 'w')
io = IO.new(fd)
IO.stubs(:popen).yields(io)
UI.with_pager do
UI.output_io.should == io
end
UI.output_io.should.be.nil
end
end
describe '#labeled' do describe '#labeled' do
it 'prints nothing if value is nil' do it 'prints nothing if value is nil' do
UI.labeled('label', nil) UI.labeled('label', nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment