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
20 21 22 23 |
# File 'lib/tty/terminal/pager.rb', line 20 def initialize(text = nil) @text = text @enabled = true end |
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/tty/terminal/pager.rb', line 8 def enabled @enabled end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
10 11 12 |
# File 'lib/tty/terminal/pager.rb', line 10 def text @text end |
Class Method Details
.available(*commands) ⇒ String
Find first available system command for paging
51 52 53 54 |
# File 'lib/tty/terminal/pager.rb', line 51 def self.available(*commands) commands = commands.empty? ? 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
59 60 61 |
# File 'lib/tty/terminal/pager.rb', line 59 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.
71 72 73 74 75 76 77 |
# File 'lib/tty/terminal/pager.rb', line 71 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
39 40 41 42 |
# File 'lib/tty/terminal/pager.rb', line 39 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
85 86 87 88 89 90 91 92 93 |
# File 'lib/tty/terminal/pager.rb', line 85 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
30 31 32 |
# File 'lib/tty/terminal/pager.rb', line 30 def enabled? !!@enabled end |