module Kramdown::ANSI::Pager
def pager(command: nil, lines: nil, &block)
-
(NilClass)
- returns nil if STDOUT is used or STDOUT is not a TTY.
Other tags:
- Yield: - yields the output IO handle for further processing
Parameters:
-
lines
(Integer
) -- the number of lines in the output (optional) -
command
(String
) -- the pager command (optional)
def pager(command: nil, lines: nil, &block) if block if my_pager = pager(command:, lines:) IO.popen(my_pager, 'w') do |output| output.sync = true yield output rescue Interrupt, Errno::EPIPE pager_reset_screen return nil ensure output.close end my_pager else yield STDOUT nil end else return unless STDOUT.tty? if lines if lines >= Tins::Terminal.lines pager(command:) end else command end end end
def pager_reset_screen
Resets the terminal screen by printing ANSI escape codes for reset, clear
def pager_reset_screen c = Term::ANSIColor STDOUT.print c.reset, c.clear_screen, c.move_home, c.show_cursor end