module Rib::Paging
Public Instance Methods
one_screen?(str)
click to toggle source
`less -F` can't cat the output, so we need to detect by ourselves. `less -X` would mess up the buffers, so it's not desired, either.
# File lib/rib/extra/paging.rb, line 22 def one_screen? str cols, lines = `tput cols`.to_i, `tput lines`.to_i (str.count("\n") + 2) <= lines && # count last line and prompt str.gsub(/\e\[[^m]*m/, '').size <= cols * lines end
page_result(str)
click to toggle source
# File lib/rib/extra/paging.rb, line 28 def page_result str less = IO.popen(pager, 'w') less.write(str) less.close_write rescue Errno::EPIPE # less quit without consuming all the input end
pager()
click to toggle source
# File lib/rib/extra/paging.rb, line 36 def pager ENV['PAGER'] || 'less -R' end
puts(str='')
click to toggle source
Print if the it fits one screen, paging it through a pager otherwise.
Calls superclass method
# File lib/rib/extra/paging.rb, line 11 def puts str='' return super if Paging.disabled? if one_screen?(str) super else page_result(str) end end