Class: TTY::Terminal::Pager
- Inherits:
-
Object
- Object
- TTY::Terminal::Pager
- Defined in:
- lib/tty/terminal/pager.rb
Overview
A class responsible for paging text inside terminal
Direct Known Subclasses
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.available(*commands) ⇒ String
Find first available system command for paging.
-
.available? ⇒ Boolean
private
Check if paging command exists.
-
.command(*commands) ⇒ String
private
Finds command to execute pager from shell commands unless configured is provided.
-
.executables ⇒ Array[String]
private
List possible executables for output paging.
-
.page(text) ⇒ Object
Pages output using configured pager.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Check if pager is enabled.
-
#initialize(text = nil) ⇒ Pager
constructor
Initialize a Pager.
Constructor Details
#initialize(text = nil) ⇒ Pager
Initialize a Pager
19 20 21 22 |
# File 'lib/tty/terminal/pager.rb', line 19 def initialize(text=nil) @text = text @enabled = true end |
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/tty/terminal/pager.rb', line 9 def enabled @enabled end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/tty/terminal/pager.rb', line 11 def text @text end |
Class Method Details
.available(*commands) ⇒ String
Find first available system command for paging
50 51 52 53 |
# File 'lib/tty/terminal/pager.rb', line 50 def self.available(*commands) commands = commands.empty? ? self.executables : commands commands.compact.uniq.find { |cmd| System.exists?(cmd) } end |
.available? ⇒ Boolean
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.
Check if paging command exists
58 59 60 |
# File 'lib/tty/terminal/pager.rb', line 58 def self.available? !!available end |
.command(*commands) ⇒ String
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.
Finds command to execute pager from shell commands unless configured is provided.
69 70 71 72 73 74 75 |
# File 'lib/tty/terminal/pager.rb', line 69 def self.command(*commands) @command = if (@command && commands.empty?) @command else available(*commands) end end |
.executables ⇒ Array[String]
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.
List possible executables for output paging
38 39 40 41 |
# File 'lib/tty/terminal/pager.rb', line 38 def self.executables [ ENV['GIT_PAGER'], `git config --get-all core.pager`.split.first, ENV['PAGER'], 'less -isr', 'more', 'cat', 'pager' ] end |
.page(text) ⇒ Object
Pages output using configured pager
83 84 85 86 87 88 89 90 91 |
# File 'lib/tty/terminal/pager.rb', line 83 def self.page(text) return unless TTY.shell.tty? if System.unix? && available? SystemPager.new(text).page else BasicPager.new(text).page end end |
Instance Method Details
#enabled? ⇒ Boolean
Check if pager is enabled
29 30 31 |
# File 'lib/tty/terminal/pager.rb', line 29 def enabled? !!@enabled end |