pry 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: d07ef96499f7a86674cffc2a3716d4d922c33046c0134585292915b27af11f70
4
- data.tar.gz: 544a3c577b01fc131ee3ab5c6a85dd89594675de8a4019a536a98afd29ee71a8
2
+ SHA1:
3
+ metadata.gz: cbf5001726c32fca4ad53946241bc627724bac43
4
+ data.tar.gz: ca594bc15a8429ecf268bd50764a9b7bc0405d21
5
5
  SHA512:
6
- metadata.gz: 0510a99ee011dd860352f7fdc7c7c5cd721fa44b2b72d7f2c354fc90af53a481ec53e1a6fc29a01fdf81f8130b756977c7d3dd885cc34418416d81f4ae7244e8
7
- data.tar.gz: a8622184f84e20196899c1629c4f45733ed57416d2cb104345099fb64842d92eb105de264627f203b047816328e1201d94b6dd876719d3dc82ab49eba5f22e5b
6
+ metadata.gz: e533b613978de9ede7463d1bdc2cc0175d23a1f3f23fabe63c36154b587f4e04fb872de6265744f4eba77844290cb515d594ec9c9a4f94f03da9485358b6f11a
7
+ data.tar.gz: 4c179399551b6b22e891b07abdc9d6b1eace0e27c53c607147d1be7522a54c9506c1d8eee35e4d42b6bead1119eb979528865422a6cb5d71b67eb224600cfcd4
@@ -1,5 +1,14 @@
1
1
  ### HEAD
2
2
 
3
+ ### [v0.12.1][v0.12.1] (November 12, 2018)
4
+
5
+ #### Bug fixes
6
+
7
+ * Stopped creating a new hash each time `Pry::Prompt#[]` is invoked
8
+ ([#1855](https://github.com/pry/pry/pull/1855))
9
+ * Fixed `less` pager not working when it's available
10
+ ([#1861](https://github.com/pry/pry/pull/1861))
11
+
3
12
  ### [v0.12.0][v0.12.0] (November 5, 2018)
4
13
 
5
14
  #### Major changes
@@ -933,3 +942,4 @@ complete CHANGELOG:
933
942
  * release!
934
943
 
935
944
  [v0.12.0]: https://github.com/pry/pry/releases/tag/v0.12.0
945
+ [v0.12.1]: https://github.com/pry/pry/releases/tag/v0.12.1
data/lib/pry.rb CHANGED
@@ -2,20 +2,19 @@ require 'pp'
2
2
  require 'pry/forwardable'
3
3
  require 'pry/input_lock'
4
4
  require 'pry/exceptions'
5
- require 'pry/platform'
6
5
  require 'pry/helpers/base_helpers'
7
6
  require 'pry/hooks'
8
7
 
9
8
  class Pry
10
9
  # The default hooks - display messages when beginning and ending Pry sessions.
11
- DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
10
+ DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |_out, _target, _pry_|
12
11
  next if _pry_.quiet?
13
12
 
14
13
  _pry_.run_command("whereami --quiet")
15
14
  end
16
15
 
17
16
  # The default print
18
- DEFAULT_PRINT = proc do |output, value, _pry_|
17
+ DEFAULT_PRINT = proc do |_output, value, _pry_|
19
18
  _pry_.pager.open do |pager|
20
19
  pager.print _pry_.config.output_prefix
21
20
  Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
@@ -191,7 +191,7 @@ Pry::CLI.add_options do
191
191
  Pry.config.requires << file
192
192
  end
193
193
 
194
- on :I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":" do |load_path|
194
+ on(:I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":") do
195
195
  load_path.map! do |path|
196
196
  /\A\.\// =~ path ? path : File.expand_path(path)
197
197
  end
@@ -199,7 +199,7 @@ Pry::CLI.add_options do
199
199
  $LOAD_PATH.unshift(*load_path)
200
200
  end
201
201
 
202
- on "gem", "Shorthand for -I./lib -rgemname" do |load_path|
202
+ on "gem", "Shorthand for -I./lib -rgemname" do |_load_path|
203
203
  $LOAD_PATH.unshift("./lib")
204
204
  Dir["./lib/*.rb"].each do |file|
205
205
  Pry.config.requires << file
@@ -252,18 +252,6 @@ class Pry
252
252
  command_set.to_hash
253
253
  end
254
254
 
255
- #
256
- # @deprecated
257
- # Please use black(), white(), etc directly instead (as you would with helper
258
- # functions from BaseHelpers and CommandHelpers)
259
- #
260
- # @return [Module]
261
- # Returns Pry::Helpers::Text
262
- #
263
- def text
264
- Pry::Helpers::Text
265
- end
266
-
267
255
  def void
268
256
  VOID_VALUE
269
257
  end
@@ -319,7 +307,10 @@ class Pry
319
307
  collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
320
308
 
321
309
  if collision_type
322
- output.puts "#{text.bold('WARNING:')} Calling Pry command '#{command_match}', which conflicts with a #{collision_type}.\n\n"
310
+ output.puts(
311
+ "#{Helpers::Text.bold('WARNING:')} Calling Pry command '#{command_match}', " \
312
+ "which conflicts with a #{collision_type}.\n\n"
313
+ )
323
314
  end
324
315
  rescue Pry::RescuableException
325
316
  end
@@ -425,9 +416,13 @@ class Pry
425
416
  unless dependencies_met?
426
417
  gems_needed = Array(command_options[:requires_gem])
427
418
  gems_not_installed = gems_needed.select { |g| !Rubygem.installed?(g) }
428
- output.puts "\nThe command '#{command_name}' is #{text.bold("unavailable")} because it requires the following gems to be installed: #{(gems_not_installed.join(", "))}"
429
- output.puts "-"
430
- output.puts "Type `install-command #{command_name}` to install the required gems and activate this command."
419
+ output.puts(<<WARN)
420
+ The command #{Helpers::Text.bold(command_name)} is unavailable because it requires the following
421
+ gems to be installed: #{(gems_not_installed.join(", "))}
422
+
423
+ Type #{Helpers::Text.bold('install-command ' + command_name)} to install the required gems
424
+ and activate this command.
425
+ WARN
431
426
  return void
432
427
  end
433
428
 
@@ -28,7 +28,7 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
28
28
  "#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt[:value]}\n" +
29
29
  prompt[:description]
30
30
  end
31
- output.puts(prompts.join("\n"))
31
+ output.puts(prompts.join("\n" * 2))
32
32
  end
33
33
 
34
34
  def change_prompt(prompt)
@@ -19,7 +19,7 @@ module Pry::Command::Ls::JRubyHacks
19
19
  m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
20
20
  end
21
21
 
22
- grouped.flat_map do |key, values|
22
+ grouped.flat_map do |_key, values|
23
23
  values = values.sort_by do |m|
24
24
  rubbishness(m.name)
25
25
  end
@@ -19,7 +19,7 @@ class Pry
19
19
  private
20
20
 
21
21
  def format(name_value_pairs)
22
- name_value_pairs.sort_by { |name, value|
22
+ name_value_pairs.sort_by { |_name, value|
23
23
  value.to_s.size
24
24
  }.reverse.map { |name, value|
25
25
  colorized_assignment_style(name, format_value(value))
@@ -155,7 +155,7 @@ class Pry
155
155
  owner: "\n#{bold("Owner:")} #{code_object.owner || "N/A"}\n",
156
156
  visibility: "#{bold("Visibility:")} #{code_object.visibility}",
157
157
  signature: "\n#{bold("Signature:")} #{code_object.signature}"
158
- }.merge(header_options) { |key, old, new| (new && old).to_s }
158
+ }.merge(header_options) { |_key, old, new| (new && old).to_s }
159
159
  end
160
160
 
161
161
  def header_options
@@ -36,7 +36,7 @@ class Pry
36
36
  if exception.respond_to? :cause
37
37
  cause = exception.cause
38
38
  while cause
39
- output.puts "#{text.bold('Caused by:')} #{cause.class}: #{cause}\n--"
39
+ output.puts "#{bold('Caused by:')} #{cause.class}: #{cause}\n--"
40
40
  if opts.verbose?
41
41
  output.puts with_line_numbers(cause.backtrace)
42
42
  else
@@ -163,8 +163,8 @@ class Pry
163
163
 
164
164
  def eager_load!
165
165
  default = @default
166
- while default
167
- default.memoized_methods.each { |method| self[key] = default.public_send(key) } if default.respond_to?(:memoized_methods)
166
+ while default && default.respond_to?(:memoized_methods)
167
+ default.memoized_methods.each { self[key] = default.public_send(key) }
168
168
  default = @default.default
169
169
  end
170
170
  end
@@ -1,135 +1,8 @@
1
1
  module Pry::Helpers; end
2
2
 
3
- # rubocop:disable Metrics/ModuleLength
4
3
  module Pry::Helpers::BaseHelpers
5
4
  extend self
6
5
 
7
- @mac_osx_warn = false
8
- # @deprecated Use {Pry::Helpers::Platform.mac_osx?} instead.
9
- def mac_osx?
10
- unless @mac_osx_warn
11
- loc = caller_locations(1..1).first
12
- warn(
13
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
14
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
15
- )
16
- @mac_osx_warn = true
17
- end
18
- Pry::Helpers::Platform.mac_osx?
19
- end
20
-
21
- @linux_warn = false
22
- # @deprecated Use {Pry::Helpers::Platform.mac_osx?} instead.
23
- def linux?
24
- unless @linux_warn
25
- loc = caller_locations(1..1).first
26
- warn(
27
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
28
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
29
- )
30
- @linux_warn = true
31
- end
32
- Pry::Helpers::Platform.linux?
33
- end
34
-
35
- @windows_warn = false
36
- # @deprecated Use {Pry::Helpers::Platform.windows?} instead.
37
- def windows?
38
- unless @windows_warn
39
- loc = caller_locations(1..1).first
40
- warn(
41
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
42
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
43
- )
44
- @windows_warn = true
45
- end
46
- Pry::Helpers::Platform.windows?
47
- end
48
-
49
- @windows_ansi_warn = false
50
- # @deprecated Use {Pry::Helpers::Platform.windows_ansi?} instead.
51
- def windows_ansi?
52
- unless @windows_ansi_warn
53
- loc = caller_locations(1..1).first
54
- warn(
55
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
56
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
57
- )
58
- @windows_ansi_warn = true
59
- end
60
- Pry::Helpers::Platform.windows_ansi?
61
- end
62
-
63
- @jruby_warn = false
64
- # @deprecated Use {Pry::Helpers::Platform.jruby?} instead.
65
- def jruby?
66
- unless @jruby_warn
67
- loc = caller_locations(1..1).first
68
- warn(
69
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
70
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
71
- )
72
- @jruby_warn = true
73
- end
74
- Pry::Helpers::Platform.jruby?
75
- end
76
-
77
- @jruby19_warn = false
78
- # @deprecated Use {Pry::Helpers::Platform.jruby_19?} instead.
79
- def jruby_19?
80
- unless @jruby19_warn
81
- loc = caller_locations(1..1).first
82
- warn(
83
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
84
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
85
- )
86
- @jruby19_warn = true
87
- end
88
- Pry::Helpers::Platform.jruby_19?
89
- end
90
-
91
- @mri_warn = false
92
- # @deprecated Use {Pry::Helpers::Platform.mri?} instead.
93
- def mri?
94
- unless @mri_warn
95
- loc = caller_locations(1..1).first
96
- warn(
97
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
98
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
99
- )
100
- @mri_warn = true
101
- end
102
- Pry::Helpers::Platform.mri?
103
- end
104
-
105
- @mri19_warn = false
106
- # @deprecated Use {Pry::Helpers::Platform.mri_19?} instead.
107
- def mri_19?
108
- unless @mri19_warn
109
- loc = caller_locations(1..1).first
110
- warn(
111
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
112
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
113
- )
114
- @mri19_warn = true
115
- end
116
- Pry::Helpers::Platform.mri_19?
117
- end
118
-
119
- @mri2_warn = false
120
- # @deprecated Use {Pry::Helpers::Platform.mri_2?} instead.
121
- def mri_2?
122
- unless @mri2_warn
123
- loc = caller_locations(1..1).first
124
- warn(
125
- "#{loc.path}:#{loc.lineno}: warning: method BaseHelpers##{__method__} " \
126
- "is deprecated. Use Pry:Helpers::Platform.#{__method__} instead"
127
- )
128
- @mri2_warn = true
129
- end
130
- Pry::Helpers::Platform.mri_2?
131
- end
132
-
133
6
  def silence_warnings
134
7
  old_verbose = $VERBOSE
135
8
  $VERBOSE = nil
@@ -197,4 +70,3 @@ module Pry::Helpers::BaseHelpers
197
70
  end
198
71
  end
199
72
  end
200
- # rubocop:enable Metrics/ModuleLength
@@ -34,7 +34,7 @@ class Pry
34
34
  # @return [Pry:Hooks] The receiver.
35
35
  # @see #merge
36
36
  def merge!(other)
37
- @hooks.merge!(other.dup.hooks) do |key, array, other_array|
37
+ @hooks.merge!(other.dup.hooks) do |_key, array, other_array|
38
38
  temp_hash, output = {}, []
39
39
 
40
40
  (array + other_array).reverse_each do |pair|
@@ -79,7 +79,7 @@ class Pry
79
79
  end
80
80
 
81
81
  # ensure we only have one anonymous hook
82
- @hooks[event_name].delete_if { |h, k| h.nil? } if hook_name.nil?
82
+ @hooks[event_name].delete_if { |h, _k| h.nil? } if hook_name.nil?
83
83
 
84
84
  if block
85
85
  @hooks[event_name] << [hook_name, block]
@@ -95,7 +95,7 @@ class Pry
95
95
  # @param [Array] args The arguments to pass to each hook function.
96
96
  # @return [Object] The return value of the last executed hook.
97
97
  def exec_hook(event_name, *args, &block)
98
- @hooks[event_name.to_s].map do |hook_name, callable|
98
+ @hooks[event_name.to_s].map do |_hook_name, callable|
99
99
  begin
100
100
  callable.call(*args, &block)
101
101
  rescue RescuableException => e
@@ -115,7 +115,7 @@ class Pry
115
115
  # @param [Symbol] hook_name The name of the hook
116
116
  # @return [#call] a specific hook for a given event.
117
117
  def get_hook(event_name, hook_name)
118
- hook = @hooks[event_name.to_s].find do |current_hook_name, callable|
118
+ hook = @hooks[event_name.to_s].find do |current_hook_name, _callable|
119
119
  current_hook_name == hook_name
120
120
  end
121
121
  hook.last if hook
@@ -145,7 +145,7 @@ class Pry
145
145
  input.lines.each do |line|
146
146
  if in_string?
147
147
  tokens = tokenize("#{open_delimiters_line}\n#{line}")
148
- tokens = tokens.drop_while { |token, type| !(String === token && token.include?("\n")) }
148
+ tokens = tokens.drop_while { |token, _type| !(String === token && token.include?("\n")) }
149
149
  previously_in_string = true
150
150
  else
151
151
  tokens = tokenize(line)
@@ -161,15 +161,6 @@ class Pry
161
161
  all_from_class(singleton_class_of(obj), include_super)
162
162
  end
163
163
 
164
- #
165
- # @deprecated
166
- # please use {all_from_obj} instead.
167
- # the `method_type` argument is ignored.
168
- #
169
- def all_from_common(obj, _method_type = nil, include_super = true)
170
- all_from_obj(obj, include_super)
171
- end
172
-
173
164
  # Get every `Class` and `Module`, in order, that will be checked when looking
174
165
  # for an instance method to call on this object.
175
166
  # @param [Object] obj
@@ -3,241 +3,248 @@ require 'pry/terminal'
3
3
  # A pager is an `IO`-like object that accepts text and either prints it
4
4
  # immediately, prints it one page at a time, or streams it to an external
5
5
  # program to print one page at a time.
6
- class Pry::Pager
7
- class StopPaging < StandardError
8
- end
9
-
10
- attr_reader :_pry_
11
-
12
- def initialize(_pry_)
13
- @_pry_ = _pry_
14
- end
15
-
16
- # Send the given text through the best available pager (if `Pry.config.pager` is
17
- # enabled). If you want to send text through in chunks as you generate it, use `open`
18
- # to get a writable object instead.
19
- #
20
- # @param [String] text
21
- # Text to run through a pager.
22
- #
23
- def page(text)
24
- open do |pager|
25
- pager << text
6
+ class Pry
7
+ class Pager
8
+ class StopPaging < StandardError
26
9
  end
27
- end
28
10
 
29
- # Yields a pager object (`NullPager`, `SimplePager`, or `SystemPager`). All
30
- # pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
31
- def open
32
- pager = best_available
33
- yield pager
34
- rescue StopPaging
35
- ensure
36
- pager.close if pager
37
- end
11
+ attr_reader :_pry_
38
12
 
39
- private
40
-
41
- def enabled?; !!@enabled; end
42
-
43
- def output; @output; end
44
-
45
- # Return an instance of the "best" available pager class -- `SystemPager` if
46
- # possible, `SimplePager` if `SystemPager` isn't available, and `NullPager`
47
- # if the user has disabled paging. All pagers accept output with `#puts`,
48
- # `#print`, `#write`, and `#<<`. You must call `#close` when you're done
49
- # writing output to a pager, and you must rescue `Pry::Pager::StopPaging`.
50
- # These requirements can be avoided by using `.open` instead.
51
- def best_available
52
- if !_pry_.config.pager
53
- NullPager.new(_pry_.output)
54
- elsif !SystemPager.available? || Helpers::Platform.jruby?
55
- SimplePager.new(_pry_.output)
56
- else
57
- SystemPager.new(_pry_.output)
13
+ def initialize(_pry_)
14
+ @_pry_ = _pry_
58
15
  end
59
- end
60
16
 
61
- # `NullPager` is a "pager" that actually just prints all output as it comes
62
- # in. Used when `Pry.config.pager` is false.
63
- class NullPager
64
- def initialize(out)
65
- @out = out
17
+ # Send the given text through the best available pager (if
18
+ # `Pry.config.pager` is enabled). If you want to send text through in
19
+ # chunks as you generate it, use `open` to get a writable object
20
+ # instead.
21
+ #
22
+ # @param [String] text
23
+ # Text to run through a pager.
24
+ #
25
+ def page(text)
26
+ open do |pager|
27
+ pager << text
28
+ end
66
29
  end
67
30
 
68
- def puts(str)
69
- print "#{str.chomp}\n"
31
+ # Yields a pager object (`NullPager`, `SimplePager`, or `SystemPager`).
32
+ # All pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
33
+ def open
34
+ pager = best_available
35
+ yield pager
36
+ rescue StopPaging
37
+ ensure
38
+ pager.close if pager
70
39
  end
71
40
 
72
- def print(str)
73
- write str
74
- end
75
- alias << print
41
+ private
76
42
 
77
- def write(str)
78
- @out.write str
43
+ def enabled?; !!@enabled; end
44
+
45
+ def output; @output; end
46
+
47
+ # Return an instance of the "best" available pager class --
48
+ # `SystemPager` if possible, `SimplePager` if `SystemPager` isn't
49
+ # available, and `NullPager` if the user has disabled paging. All
50
+ # pagers accept output with `#puts`, `#print`, `#write`, and `#<<`. You
51
+ # must call `#close` when you're done writing output to a pager, and
52
+ # you must rescue `Pry::Pager::StopPaging`. These requirements can be
53
+ # avoided by using `.open` instead.
54
+ def best_available
55
+ if !_pry_.config.pager
56
+ NullPager.new(_pry_.output)
57
+ elsif !SystemPager.available? || Helpers::Platform.jruby?
58
+ SimplePager.new(_pry_.output)
59
+ else
60
+ SystemPager.new(_pry_.output)
61
+ end
79
62
  end
80
63
 
81
- def close
82
- end
64
+ # `NullPager` is a "pager" that actually just prints all output as it
65
+ # comes in. Used when `Pry.config.pager` is false.
66
+ class NullPager
67
+ def initialize(out)
68
+ @out = out
69
+ end
83
70
 
84
- private
71
+ def puts(str)
72
+ print "#{str.chomp}\n"
73
+ end
85
74
 
86
- def height
87
- @height ||= Pry::Terminal.height!
88
- end
75
+ def print(str)
76
+ write str
77
+ end
78
+ alias << print
89
79
 
90
- def width
91
- @width ||= Pry::Terminal.width!
92
- end
93
- end
80
+ def write(str)
81
+ @out.write str
82
+ end
94
83
 
95
- # `SimplePager` is a straightforward pure-Ruby pager. We use it on JRuby and
96
- # when we can't find a usable external pager.
97
- class SimplePager < NullPager
98
- def initialize(*)
99
- super
100
- @tracker = PageTracker.new(height - 3, width)
101
- end
84
+ def close
85
+ end
102
86
 
103
- def write(str)
104
- str.lines.each do |line|
105
- @out.print line
106
- @tracker.record line
87
+ private
107
88
 
108
- if @tracker.page?
109
- @out.print "\n"
110
- @out.print "\e[0m"
111
- @out.print "<page break> --- Press enter to continue " \
112
- "( q<enter> to break ) --- <page break>\n"
113
- raise StopPaging if Readline.readline("").chomp == "q"
89
+ def height
90
+ @height ||= Pry::Terminal.height!
91
+ end
114
92
 
115
- @tracker.reset
116
- end
93
+ def width
94
+ @width ||= Pry::Terminal.width!
117
95
  end
118
96
  end
119
- end
120
97
 
121
- # `SystemPager` buffers output until we're pretty sure it's at least a page
122
- # long, then invokes an external pager and starts streaming output to it. If
123
- # `#close` is called before then, it just prints out the buffered content.
124
- class SystemPager < NullPager
125
- def self.default_pager
126
- pager = ENV["PAGER"] || ""
127
-
128
- # Default to less, and make sure less is being passed the correct options
129
- if pager.strip.empty? or pager =~ /^less\b/
130
- pager = "less -R -F -X"
98
+ # `SimplePager` is a straightforward pure-Ruby pager. We use it on
99
+ # JRuby and when we can't find a usable external pager.
100
+ class SimplePager < NullPager
101
+ def initialize(*)
102
+ super
103
+ @tracker = PageTracker.new(height - 3, width)
131
104
  end
132
105
 
133
- pager
134
- end
106
+ def write(str)
107
+ str.lines.each do |line|
108
+ @out.print line
109
+ @tracker.record line
135
110
 
136
- @system_pager = nil
111
+ if @tracker.page?
112
+ @out.print "\n"
113
+ @out.print "\e[0m"
114
+ @out.print "<page break> --- Press enter to continue " \
115
+ "( q<enter> to break ) --- <page break>\n"
116
+ raise StopPaging if Readline.readline("").chomp == "q"
137
117
 
138
- def self.available?
139
- if @system_pager.nil?
140
- @system_pager = begin
141
- pager_executable = default_pager.split(' ').first
142
- if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
143
- `where /Q #{pager_executable}`
144
- else
145
- `which #{pager_executable}`
118
+ @tracker.reset
146
119
  end
147
- $?.success?
148
- rescue
149
- false
150
120
  end
151
- else
152
- @system_pager
153
121
  end
154
122
  end
155
123
 
156
- def initialize(*)
157
- super
158
- @tracker = PageTracker.new(height, width)
159
- @buffer = ""
160
- @pager = nil
161
- end
124
+ # `SystemPager` buffers output until we're pretty sure it's at least a
125
+ # page long, then invokes an external pager and starts streaming output
126
+ # to it. If `#close` is called before then, it just prints out the
127
+ # buffered content.
128
+ class SystemPager < NullPager
129
+ def self.default_pager
130
+ pager = ENV["PAGER"] || ""
162
131
 
163
- def write(str)
164
- if invoked_pager?
165
- write_to_pager str
166
- else
167
- @tracker.record str
168
- @buffer << str
132
+ # Default to less, and make sure less is being passed the correct
133
+ # options
134
+ if pager.strip.empty? or pager =~ /^less\b/
135
+ pager = "less -R -F -X"
136
+ end
137
+
138
+ pager
139
+ end
169
140
 
170
- if @tracker.page?
171
- write_to_pager @buffer
141
+ @system_pager = nil
142
+
143
+ def self.available?
144
+ if @system_pager.nil?
145
+ @system_pager = begin
146
+ pager_executable = default_pager.split(' ').first
147
+ if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
148
+ `where /Q #{pager_executable}`
149
+ else
150
+ `which #{pager_executable}`
151
+ end
152
+ $?.success?
153
+ rescue
154
+ false
155
+ end
156
+ else
157
+ @system_pager
172
158
  end
173
159
  end
174
- rescue Errno::EPIPE
175
- raise StopPaging
176
- end
177
160
 
178
- def close
179
- if invoked_pager?
180
- pager.close
181
- else
182
- @out.puts @buffer
161
+ def initialize(*)
162
+ super
163
+ @tracker = PageTracker.new(height, width)
164
+ @buffer = ""
165
+ @pager = nil
183
166
  end
184
- end
185
167
 
186
- private
168
+ def write(str)
169
+ if invoked_pager?
170
+ write_to_pager str
171
+ else
172
+ @tracker.record str
173
+ @buffer << str
187
174
 
188
- def write_to_pager(text)
189
- pager.write @out.decolorize_maybe(text)
190
- end
175
+ if @tracker.page?
176
+ write_to_pager @buffer
177
+ end
178
+ end
179
+ rescue Errno::EPIPE
180
+ raise StopPaging
181
+ end
191
182
 
192
- def invoked_pager?
193
- @pager
194
- end
183
+ def close
184
+ if invoked_pager?
185
+ pager.close
186
+ else
187
+ @out.puts @buffer
188
+ end
189
+ end
195
190
 
196
- def pager
197
- @pager ||= IO.popen(self.class.default_pager, 'w')
198
- end
199
- end
191
+ private
200
192
 
201
- # `PageTracker` tracks output to determine whether it's likely to take up a
202
- # whole page. This doesn't need to be super precise, but we can use it for
203
- # `SimplePager` and to avoid invoking the system pager unnecessarily.
204
- #
205
- # One simplifying assumption is that we don't need `#page?` to return `true`
206
- # on the basis of an incomplete line. Long lines should be counted as
207
- # multiple lines, but we don't have to transition from `false` to `true`
208
- # until we see a newline.
209
- class PageTracker
210
- def initialize(rows, cols)
211
- @rows, @cols = rows, cols
212
- reset
193
+ def write_to_pager(text)
194
+ pager.write @out.decolorize_maybe(text)
195
+ end
196
+
197
+ def invoked_pager?
198
+ @pager
199
+ end
200
+
201
+ def pager
202
+ @pager ||= IO.popen(self.class.default_pager, 'w')
203
+ end
213
204
  end
214
205
 
215
- def record(str)
216
- str.lines.each do |line|
217
- if line.end_with? "\n"
218
- @row += ((@col + line_length(line) - 1) / @cols) + 1
219
- @col = 0
220
- else
221
- @col += line_length(line)
206
+ # `PageTracker` tracks output to determine whether it's likely to take
207
+ # up a whole page. This doesn't need to be super precise, but we can
208
+ # use it for `SimplePager` and to avoid invoking the system pager
209
+ # unnecessarily.
210
+ #
211
+ # One simplifying assumption is that we don't need `#page?` to return
212
+ # `true` on the basis of an incomplete line. Long lines should be
213
+ # counted as multiple lines, but we don't have to transition from
214
+ # `false` to `true` until we see a newline.
215
+ class PageTracker
216
+ def initialize(rows, cols)
217
+ @rows, @cols = rows, cols
218
+ reset
219
+ end
220
+
221
+ def record(str)
222
+ str.lines.each do |line|
223
+ if line.end_with? "\n"
224
+ @row += ((@col + line_length(line) - 1) / @cols) + 1
225
+ @col = 0
226
+ else
227
+ @col += line_length(line)
228
+ end
222
229
  end
223
230
  end
224
- end
225
231
 
226
- def page?
227
- @row >= @rows
228
- end
232
+ def page?
233
+ @row >= @rows
234
+ end
229
235
 
230
- def reset
231
- @row = 0
232
- @col = 0
233
- end
236
+ def reset
237
+ @row = 0
238
+ @col = 0
239
+ end
234
240
 
235
- private
241
+ private
236
242
 
237
- # Approximation of the printable length of a given line, without the
238
- # newline and without ANSI color codes.
239
- def line_length(line)
240
- line.chomp.gsub(/\e\[[\d;]*m/, '').length
243
+ # Approximation of the printable length of a given line, without the
244
+ # newline and without ANSI color codes.
245
+ def line_length(line)
246
+ line.chomp.gsub(/\e\[[\d;]*m/, '').length
247
+ end
241
248
  end
242
249
  end
243
250
  end
@@ -27,10 +27,6 @@ class Pry
27
27
  # 1-line #inspect output suitable for prompt
28
28
  SAFE_CONTEXTS = [String, Numeric, Symbol, nil, true, false].freeze
29
29
 
30
- # @deprecated Use {Pry::Prompt.add} instead.
31
- MAP = {}
32
- deprecate_constant(:MAP) if respond_to?(:deprecate_constant)
33
-
34
30
  # A Hash that holds all prompts. The keys of the Hash are prompt
35
31
  # names, the values are Hash instances of the format {:description, :value}.
36
32
  @prompts = {}
@@ -45,7 +41,7 @@ class Pry
45
41
  # @return [Hash{Symbol=>Object}]
46
42
  # @since v0.12.0
47
43
  def [](prompt_name)
48
- all[prompt_name.to_s]
44
+ @prompts[prompt_name.to_s]
49
45
  end
50
46
 
51
47
  # @return [Hash{Symbol=>Hash}] the duplicate of the internal prompts hash
@@ -94,11 +90,10 @@ class Pry
94
90
  end
95
91
  end
96
92
 
97
- add(:default, <<DESC) do |context, nesting, _pry_, sep|
98
- The default Pry prompt. Includes information about the current expression
99
- number, evaluation context, and nesting level, plus a reminder that you're
100
- using Pry.
101
- DESC
93
+ add 'default',
94
+ "The default Pry prompt. Includes information about the current expression \n" \
95
+ "number, evaluation context, and nesting level, plus a reminder that you're \n" \
96
+ 'using Pry.' do |context, nesting, _pry_, sep|
102
97
  format(
103
98
  "[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ",
104
99
  in_count: _pry_.input_ring.count,
@@ -109,14 +104,20 @@ DESC
109
104
  )
110
105
  end
111
106
 
112
- add(:simple, "A simple `>>`.\n", ['>> ', ' | ']) do |_, _, _, sep|
107
+ add(
108
+ 'simple',
109
+ "A simple `>>`.",
110
+ ['>> ', ' | ']
111
+ ) do |_, _, _, sep|
113
112
  sep
114
113
  end
115
114
 
116
- add(:nav, <<DESC, %w[> *]) do |context, nesting, _pry_, sep|
117
- A prompt that displays the binding stack as a path and includes information
118
- about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.
119
- DESC
115
+ add(
116
+ 'nav',
117
+ "A prompt that displays the binding stack as a path and includes information \n" \
118
+ "about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.",
119
+ %w[> *]
120
+ ) do |_context, _nesting, _pry_, sep|
120
121
  tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval('self')) }
121
122
  format(
122
123
  "[%<in_count>s] (%<name>s) %<tree>s: %<stack_size>s%<separator>s ",
@@ -128,9 +129,11 @@ DESC
128
129
  )
129
130
  end
130
131
 
131
- add(:shell, <<DESC, %w[$ *]) do |context, nesting, _pry_, sep|
132
- A prompt that displays `$PWD` as you change it.
133
- DESC
132
+ add(
133
+ 'shell',
134
+ 'A prompt that displays `$PWD` as you change it.',
135
+ %w[$ *]
136
+ ) do |context, _nesting, _pry_, sep|
134
137
  format(
135
138
  "%<name>s %<context>s:%<pwd>s %<separator>s ",
136
139
  name: prompt_name(_pry_.config.prompt_name),
@@ -140,6 +143,10 @@ DESC
140
143
  )
141
144
  end
142
145
 
143
- add(:none, 'Wave goodbye to the Pry prompt.', Array.new(2)) { '' }
146
+ add(
147
+ 'none',
148
+ 'Wave goodbye to the Pry prompt.',
149
+ Array.new(2)
150
+ ) { '' }
144
151
  end
145
152
  end
@@ -87,36 +87,6 @@ class Pry
87
87
  exec_hook(:when_started, target, options, self)
88
88
  end
89
89
 
90
- @input_array_warn = false
91
- # @deprecated Use {#input_ring} instead.
92
- def input_array
93
- unless @input_array_warn
94
- loc = caller_locations(1..1).first
95
- warn(
96
- "#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
97
- "is deprecated. Use #{self.class}#input_ring instead"
98
- )
99
- @input_array_warn = true
100
- end
101
-
102
- @input_ring
103
- end
104
-
105
- @output_array_warn = false
106
- # @deprecated Use {#output_ring} instead.
107
- def output_array
108
- unless @output_array_warn
109
- loc = caller_locations(1..1).first
110
- warn(
111
- "#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
112
- "is deprecated. Use #{self.class}#output_ring instead"
113
- )
114
- @output_array_warn = true
115
- end
116
-
117
- @output_ring
118
- end
119
-
120
90
  # This is the prompt at the top of the prompt stack.
121
91
  # @return [Array<Proc>] the current prompt
122
92
  def prompt
@@ -34,7 +34,7 @@ class Pry
34
34
  # @param [Pry] _pry_ the Pry instance to make non-interactive.
35
35
  def non_interactive_mode(_pry_, content)
36
36
  _pry_.print = proc {}
37
- _pry_.exception_handler = proc do |o, e, _p_|
37
+ _pry_.exception_handler = proc do |o, _e, _p_|
38
38
  _p_.run_command "cat --ex"
39
39
  o.puts "...exception encountered, going interactive!"
40
40
  interactive_mode(_pry_)
@@ -224,7 +224,7 @@ class Pry::Slop
224
224
  autocreate(items, index) if config[:autocreate]
225
225
  process_item(items, index, &block) unless @trash.include?(index)
226
226
  end
227
- items.reject!.with_index { |item, index| @trash.include?(index) }
227
+ items.reject!.with_index { |_item, index| @trash.include?(index) }
228
228
 
229
229
  missing_options = options.select { |opt| opt.required? && opt.count < 1 }
230
230
  if missing_options.any?
@@ -45,7 +45,7 @@ class Pry::Slop
45
45
  integer: proc { |v| value_to_integer(v) },
46
46
  float: proc { |v| value_to_float(v) },
47
47
  range: proc { |v| value_to_range(v) },
48
- count: proc { |v| @count }
48
+ count: proc { @count }
49
49
  }
50
50
 
51
51
  if long && long.size > @slop.config[:longest_flag]
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = '0.12.0'
2
+ VERSION = '0.12.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  - Conrad Irwin
9
9
  - Ryan Fitzgerald
10
10
  - Kyrylo Silin
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-11-04 00:00:00.000000000 Z
14
+ date: 2018-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
+ name: coderay
17
18
  requirement: !ruby/object:Gem::Requirement
18
19
  requirements:
19
20
  - - "~>"
20
21
  - !ruby/object:Gem::Version
21
22
  version: 1.1.0
22
- name: coderay
23
- prerelease: false
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.1.0
30
30
  - !ruby/object:Gem::Dependency
31
+ name: method_source
31
32
  requirement: !ruby/object:Gem::Requirement
32
33
  requirements:
33
34
  - - "~>"
34
35
  - !ruby/object:Gem::Version
35
36
  version: 0.9.0
36
- name: method_source
37
- prerelease: false
38
37
  type: :runtime
38
+ prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
@@ -173,7 +173,6 @@ files:
173
173
  - lib/pry/object_path.rb
174
174
  - lib/pry/output.rb
175
175
  - lib/pry/pager.rb
176
- - lib/pry/platform.rb
177
176
  - lib/pry/plugins.rb
178
177
  - lib/pry/prompt.rb
179
178
  - lib/pry/pry_class.rb
@@ -200,7 +199,7 @@ homepage: http://pryrepl.org
200
199
  licenses:
201
200
  - MIT
202
201
  metadata: {}
203
- post_install_message:
202
+ post_install_message:
204
203
  rdoc_options: []
205
204
  require_paths:
206
205
  - lib
@@ -215,9 +214,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
214
  - !ruby/object:Gem::Version
216
215
  version: '0'
217
216
  requirements: []
218
- rubyforge_project:
219
- rubygems_version: 2.7.6
220
- signing_key:
217
+ rubyforge_project:
218
+ rubygems_version: 2.6.13
219
+ signing_key:
221
220
  specification_version: 4
222
221
  summary: An IRB alternative and runtime developer console
223
222
  test_files: []
@@ -1,91 +0,0 @@
1
- class Pry
2
- module Platform
3
- extend self
4
-
5
- #
6
- # @return [Boolean]
7
- # Returns true if Pry is running on Mac OSX.
8
- #
9
- # @note
10
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
11
- #
12
- def mac_osx?
13
- !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
14
- end
15
-
16
- #
17
- # @return [Boolean]
18
- # Returns true if Pry is running on Linux.
19
- #
20
- # @note
21
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
22
- #
23
- def linux?
24
- !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
25
- end
26
-
27
- #
28
- # @return [Boolean]
29
- # Returns true if Pry is running on Windows.
30
- #
31
- # @note
32
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
33
- #
34
- def windows?
35
- !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
36
- end
37
-
38
- #
39
- # @return [Boolean]
40
- # Returns true when Pry is running on Windows with ANSI support.
41
- #
42
- def windows_ansi?
43
- return false if not windows?
44
-
45
- !!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
46
- end
47
-
48
- #
49
- # @return [Boolean]
50
- # Returns true when Pry is being run from JRuby.
51
- #
52
- def jruby?
53
- RbConfig::CONFIG['ruby_install_name'] == 'jruby'
54
- end
55
-
56
- #
57
- # @return [Boolean]
58
- # Returns true when Pry is being run from JRuby in 1.9 mode.
59
- #
60
- def jruby_19?
61
- jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
62
- end
63
-
64
- #
65
- # @return [Boolean]
66
- # Returns true when Pry is being run from MRI (CRuby).
67
- #
68
- def mri?
69
- RbConfig::CONFIG['ruby_install_name'] == 'ruby'
70
- end
71
-
72
- #
73
- # @return [Boolean]
74
- # Returns true when Pry is being run from MRI v1.9+ (CRuby).
75
- #
76
- def mri_19?
77
- !!(mri? and RUBY_VERSION =~ /\A1\.9/)
78
- end
79
-
80
- #
81
- # @return [Boolean]
82
- # Returns true when Pry is being run from MRI v2+ (CRuby).
83
- #
84
- def mri_2?
85
- !!(mri? and RUBY_VERSION =~ /\A2/)
86
- end
87
- end
88
-
89
- # Not supported on MRI 2.2 and lower.
90
- deprecate_constant(:Platform) if respond_to?(:deprecate_constant)
91
- end