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
Methods inherited from NullPager
#height, #print, #puts, #width
Constructor Details
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
= .split(' ').first
if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
`where /Q #{}`
else
`which #{}`
end
$CHILD_STATUS.success?
rescue StandardError
false
end
else
@system_pager
end
end
|
130
131
132
133
134
135
136
137
138
|
# File 'lib/pry/pager.rb', line 130
def self.
= Pry::Env['PAGER'] || ''
= "less -R -F -X" if .strip.empty? || =~ /^less\b/
end
|
Instance Method Details
181
182
183
184
185
186
187
|
# File 'lib/pry/pager.rb', line 181
def close
if
.close
else
@out.puts @buffer
end
end
|
195
196
197
|
# File 'lib/pry/pager.rb', line 195
def
@pager
end
|
199
200
201
|
# File 'lib/pry/pager.rb', line 199
def
@pager ||= IO.popen(self.class., 'w')
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
str
else
@tracker.record str
@buffer += str
@buffer if @tracker.page?
end
rescue Errno::EPIPE
raise StopPaging
end
|
191
192
193
|
# File 'lib/pry/pager.rb', line 191
def (text)
.write @out.decolorize_maybe(text)
end
|