lib/rib/extra/paging.rb in rib-1.2.2 vs lib/rib/extra/paging.rb in rib-1.2.3
- old
+ new
@@ -8,10 +8,11 @@
# --------------- Rib API ---------------
# Print result if the it fits one screen,
# paging it through a pager otherwise.
def print_result result
+ return super if Paging.disabled?
output = format_result(result)
if one_screen?(output)
puts output
else
page_result(output)
@@ -30,13 +31,20 @@
def page_result output
less = IO.popen(pager, 'w')
less.write(output)
less.close_write
- rescue Errno::EPIPE => e
- Rib.warn("Error while paging result:\n #{format_error(e)}")
+ rescue Errno::EPIPE
+ # less quit without consuming all the input
end
def pager
ENV['PAGER'] || 'less -R'
end
+end
+
+pager = ENV['PAGER'] || 'less'
+
+if `which #{pager}`.empty?
+ Rib.warn("#{pager} is not available, disabling Rib::Paging")
+ Rib::Paging.disable
end