Module: Utils::Pager

Defined in:
lib/utils/pager.rb

Class Method Summary collapse

Class Method Details

.pager(command: nil, lines: nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/utils/pager.rb', line 7

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
        output.close
      end
    else
      yield STDOUT
    end
  else
    return unless STDOUT.tty?
    if lines
      if lines >= Tins::Terminal.lines
        pager(command:)
      end
    else
      command
    end
  end
end