Module: Rib::Paging
- Extended by:
- Plugin
- Defined in:
- lib/rib/extra/paging.rb
Instance Attribute Summary
Attributes included from Plugin
Instance Method Summary collapse
-
#one_screen?(str) ⇒ Boolean
‘less -F` can’t cat the output, so we need to detect by ourselves.
- #page_result(str) ⇒ Object
- #pager ⇒ Object
-
#puts(str = '') ⇒ Object
Print if the it fits one screen, paging it through a pager otherwise.
Methods included from Plugin
const_missing, disable, disabled?, enable, enabled?, extended
Instance Method Details
#one_screen?(str) ⇒ Boolean
‘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.
22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 |
# File 'lib/rib/extra/paging.rb', line 36 def pager ENV['PAGER'] || 'less -R' end |