Class: Pry::Pager::SystemPager
Overview
‘SystemPager` buffers output until we’re pretty sure it’s at least a page long, then invokes an external pager and starts streaming output to it. If ‘#close` is called before then, it just prints out the buffered content.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ SystemPager
constructor
A new instance of SystemPager.
- #write(str) ⇒ Object
Methods inherited from NullPager
Constructor Details
#initialize ⇒ SystemPager
Returns a new instance of SystemPager.
161 162 163 164 165 166 |
# File 'lib/pry/pager.rb', line 161 def initialize(*) super @tracker = PageTracker.new(height, width) @buffer = "" @pager = nil end |
Class Method Details
.available? ⇒ Boolean
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/pry/pager.rb', line 142 def self.available? if @system_pager.nil? @system_pager = begin pager_executable = default_pager.split(' ').first if Helpers::Platform.windows? || Helpers::Platform.windows_ansi? `where /Q #{pager_executable}` else `which #{pager_executable}` end $CHILD_STATUS.success? rescue StandardError false end else @system_pager end end |
.default_pager ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/pry/pager.rb', line 130 def self.default_pager pager = Pry::Env['PAGER'] || '' # Default to less, and make sure less is being passed the correct # options pager = "less -R -F -X" if pager.strip.empty? || pager =~ /^less\b/ pager end |
Instance Method Details
#close ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/pry/pager.rb', line 181 def close if invoked_pager? pager.close else @out.puts @buffer end end |
#write(str) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/pry/pager.rb', line 168 def write(str) if invoked_pager? write_to_pager str else @tracker.record str @buffer += str write_to_pager @buffer if @tracker.page? end rescue Errno::EPIPE raise StopPaging end |