Module: TTY::Pager::ClassMethods
- Included in:
- TTY::Pager
- Defined in:
- lib/tty/pager.rb
Instance Method Summary collapse
-
#new(enabled: true, command: nil, **options) ⇒ Object
Create a pager.
-
#page(text = nil, path: nil, enabled: true, command: nil, **options, &block) ⇒ Object
Paginate content through null, basic or system pager.
-
#select_pager(enabled: true, command: nil) ⇒ Object
private
Select an appriopriate pager.
Instance Method Details
#new(enabled: true, command: nil, **options) ⇒ Object
Create a pager
37 38 39 40 |
# File 'lib/tty/pager.rb', line 37 def new(enabled: true, command: nil, **) select_pager(enabled: enabled, command: command).new( enabled: enabled, command: command, **) end |
#page(text = nil, path: nil, enabled: true, command: nil, **options, &block) ⇒ Object
Paginate content through null, basic or system pager.
63 64 65 66 67 68 |
# File 'lib/tty/pager.rb', line 63 def page(text = nil, path: nil, enabled: true, command: nil, **, &block) select_pager(enabled: enabled, command: command). page(text, path: path, enabled: enabled, command: command, **, &block) end |
#select_pager(enabled: true, command: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Select an appriopriate pager
If the user disabled paging then a NullPager is returned, otherwise a check is performed to find native system command to perform pagination with SystemPager. Finally, if no system command is found, a BasicPager is used which is a pure Ruby implementation known to work on any platform.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tty/pager.rb', line 84 def select_pager(enabled: true, command: nil) commands = Array(command) if !enabled NullPager elsif SystemPager.exec_available?(*commands) SystemPager else BasicPager end end |