pry 0.10.3 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +251 -16
  3. data/LICENSE +1 -1
  4. data/README.md +35 -51
  5. data/bin/pry +3 -11
  6. data/lib/pry/basic_object.rb +6 -0
  7. data/lib/pry/cli.rb +50 -52
  8. data/lib/pry/code/code_file.rb +13 -6
  9. data/lib/pry/code/code_range.rb +3 -3
  10. data/lib/pry/code/loc.rb +14 -8
  11. data/lib/pry/code.rb +12 -5
  12. data/lib/pry/code_object.rb +27 -4
  13. data/lib/pry/color_printer.rb +20 -10
  14. data/lib/pry/command.rb +76 -45
  15. data/lib/pry/command_set.rb +17 -45
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat/exception_formatter.rb +10 -8
  19. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/cat.rb +7 -6
  22. data/lib/pry/commands/change_prompt.rb +29 -9
  23. data/lib/pry/commands/clear_screen.rb +14 -0
  24. data/lib/pry/commands/code_collector.rb +25 -23
  25. data/lib/pry/commands/easter_eggs.rb +12 -12
  26. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  27. data/lib/pry/commands/edit.rb +15 -10
  28. data/lib/pry/commands/exit.rb +2 -1
  29. data/lib/pry/commands/find_method.rb +12 -14
  30. data/lib/pry/commands/gem_cd.rb +1 -1
  31. data/lib/pry/commands/gem_install.rb +2 -2
  32. data/lib/pry/commands/gem_list.rb +2 -2
  33. data/lib/pry/commands/gem_open.rb +2 -2
  34. data/lib/pry/commands/gem_readme.rb +25 -0
  35. data/lib/pry/commands/gem_search.rb +40 -0
  36. data/lib/pry/commands/gem_stats.rb +83 -0
  37. data/lib/pry/commands/gist.rb +7 -6
  38. data/lib/pry/commands/help.rb +3 -3
  39. data/lib/pry/commands/hist.rb +11 -10
  40. data/lib/pry/commands/import_set.rb +2 -1
  41. data/lib/pry/commands/install_command.rb +7 -6
  42. data/lib/pry/commands/jump_to.rb +7 -7
  43. data/lib/pry/commands/list_inspectors.rb +2 -2
  44. data/lib/pry/commands/ls/constants.rb +14 -3
  45. data/lib/pry/commands/ls/formatter.rb +4 -2
  46. data/lib/pry/commands/ls/globals.rb +0 -2
  47. data/lib/pry/commands/ls/grep.rb +0 -2
  48. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  49. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  50. data/lib/pry/commands/ls/local_names.rb +0 -2
  51. data/lib/pry/commands/ls/local_vars.rb +0 -2
  52. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  53. data/lib/pry/commands/ls/methods.rb +0 -3
  54. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  55. data/lib/pry/commands/ls/self_methods.rb +2 -1
  56. data/lib/pry/commands/ls.rb +30 -31
  57. data/lib/pry/commands/play.rb +3 -4
  58. data/lib/pry/commands/pry_backtrace.rb +1 -1
  59. data/lib/pry/commands/raise_up.rb +2 -1
  60. data/lib/pry/commands/reload_code.rb +2 -2
  61. data/lib/pry/commands/ri.rb +9 -4
  62. data/lib/pry/commands/shell_command.rb +36 -9
  63. data/lib/pry/commands/shell_mode.rb +6 -6
  64. data/lib/pry/commands/show_doc.rb +5 -7
  65. data/lib/pry/commands/show_info.rb +41 -20
  66. data/lib/pry/commands/show_source.rb +5 -2
  67. data/lib/pry/commands/stat.rb +1 -1
  68. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  69. data/lib/pry/commands/watch_expression.rb +9 -7
  70. data/lib/pry/commands/whereami.rb +16 -9
  71. data/lib/pry/commands/wtf.rb +15 -2
  72. data/lib/pry/config/behavior.rb +230 -114
  73. data/lib/pry/config/convenience.rb +24 -21
  74. data/lib/pry/config/default.rb +151 -153
  75. data/lib/pry/config/memoization.rb +48 -0
  76. data/lib/pry/config.rb +30 -19
  77. data/lib/pry/core_extensions.rb +15 -4
  78. data/lib/pry/editor.rb +5 -12
  79. data/lib/pry/exceptions.rb +1 -3
  80. data/lib/pry/forwardable.rb +23 -0
  81. data/lib/pry/helpers/base_helpers.rb +197 -110
  82. data/lib/pry/helpers/command_helpers.rb +5 -4
  83. data/lib/pry/helpers/documentation_helpers.rb +3 -2
  84. data/lib/pry/helpers/options_helpers.rb +6 -6
  85. data/lib/pry/helpers/platform.rb +58 -0
  86. data/lib/pry/helpers/table.rb +20 -15
  87. data/lib/pry/helpers/text.rb +82 -74
  88. data/lib/pry/helpers.rb +1 -0
  89. data/lib/pry/history.rb +44 -10
  90. data/lib/pry/hooks.rb +50 -109
  91. data/lib/pry/indent.rb +21 -19
  92. data/lib/pry/input_completer.rb +146 -123
  93. data/lib/pry/input_lock.rb +0 -2
  94. data/lib/pry/last_exception.rb +2 -2
  95. data/lib/pry/method/disowned.rb +3 -1
  96. data/lib/pry/method/patcher.rb +2 -5
  97. data/lib/pry/method/weird_method_locator.rb +21 -11
  98. data/lib/pry/method.rb +44 -38
  99. data/lib/pry/object_path.rb +5 -4
  100. data/lib/pry/output.rb +37 -37
  101. data/lib/pry/pager.rb +195 -181
  102. data/lib/pry/platform.rb +91 -0
  103. data/lib/pry/plugins.rb +27 -8
  104. data/lib/pry/prompt.rb +144 -25
  105. data/lib/pry/pry_class.rb +83 -33
  106. data/lib/pry/pry_instance.rb +94 -59
  107. data/lib/pry/repl.rb +70 -11
  108. data/lib/pry/repl_file_loader.rb +2 -3
  109. data/lib/pry/ring.rb +84 -0
  110. data/lib/pry/rubygem.rb +9 -7
  111. data/lib/pry/slop/LICENSE +20 -0
  112. data/lib/pry/slop/commands.rb +195 -0
  113. data/lib/pry/slop/option.rb +206 -0
  114. data/lib/pry/slop.rb +661 -0
  115. data/lib/pry/terminal.rb +18 -6
  116. data/lib/pry/testable/evalable.rb +15 -0
  117. data/lib/pry/testable/mockable.rb +14 -0
  118. data/lib/pry/testable/pry_tester.rb +73 -0
  119. data/lib/pry/testable/utility.rb +26 -0
  120. data/lib/pry/testable/variables.rb +46 -0
  121. data/lib/pry/testable.rb +70 -0
  122. data/lib/pry/version.rb +1 -1
  123. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
  124. data/lib/pry/wrapped_module.rb +22 -21
  125. data/lib/pry.rb +21 -50
  126. metadata +35 -46
  127. data/lib/pry/commands/list_prompts.rb +0 -35
  128. data/lib/pry/commands/simple_prompt.rb +0 -22
  129. data/lib/pry/history_array.rb +0 -121
  130. data/lib/pry/rbx_path.rb +0 -22
  131. data/lib/pry/test/helper.rb +0 -170
@@ -1,113 +1,200 @@
1
- class Pry
2
- module Helpers
3
-
4
- module BaseHelpers
5
-
6
- module_function
7
-
8
- def silence_warnings
9
- old_verbose = $VERBOSE
10
- $VERBOSE = nil
11
- begin
12
- yield
13
- ensure
14
- $VERBOSE = old_verbose
15
- end
16
- end
17
-
18
- # Acts like send but ignores any methods defined below Object or Class in the
19
- # inheritance hierarchy.
20
- # This is required to introspect methods on objects like Net::HTTP::Get that
21
- # have overridden the `method` method.
22
- def safe_send(obj, method, *args, &block)
23
- (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
24
- end
25
- public :safe_send
26
-
27
- def find_command(name, set = Pry::Commands)
28
- command_match = set.find do |_, command|
29
- (listing = command.options[:listing]) == name && listing != nil
30
- end
31
- command_match.last if command_match
32
- end
33
-
34
- def not_a_real_file?(file)
35
- file =~ /(\(.*\))|<.*>/ || file =~ /__unknown__/ || file == "" || file == "-e"
36
- end
37
-
38
- def command_dependencies_met?(options)
39
- return true if !options[:requires_gem]
40
- Array(options[:requires_gem]).all? do |g|
41
- Rubygem.installed?(g)
42
- end
43
- end
44
-
45
- def use_ansi_codes?
46
- windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
47
- end
48
-
49
- def colorize_code(code)
50
- CodeRay.scan(code, :ruby).term
51
- end
52
-
53
- def highlight(string, regexp, highlight_color=:bright_yellow)
54
- string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
55
- end
56
-
57
- # formatting
58
- def heading(text)
59
- text = "#{text}\n--"
60
- "\e[1m#{text}\e[0m"
61
- end
62
-
63
- # have fun on the Windows platform.
64
- def windows?
65
- RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
66
- end
67
-
68
- # are we able to use ansi on windows?
69
- def windows_ansi?
70
- defined?(Win32::Console) || ENV['ANSICON'] || (windows? && mri_2?)
71
- end
72
-
73
- def jruby?
74
- RbConfig::CONFIG['ruby_install_name'] == 'jruby'
75
- end
76
-
77
- def jruby_19?
78
- jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
79
- end
80
-
81
- def rbx?
82
- RbConfig::CONFIG['ruby_install_name'] == 'rbx'
83
- end
84
-
85
- def mri?
86
- RbConfig::CONFIG['ruby_install_name'] == 'ruby'
87
- end
88
-
89
- def mri_19?
90
- mri? && RUBY_VERSION =~ /^1\.9/
91
- end
92
-
93
- def mri_2?
94
- mri? && RUBY_VERSION =~ /^2/
95
- end
96
-
97
- def mri_20?
98
- mri? && RUBY_VERSION =~ /^2\.0/
99
- end
100
-
101
- def mri_21?
102
- mri? && RUBY_VERSION =~ /^2\.1/
103
- end
104
-
105
- # Send the given text through the best available pager (if Pry.config.pager is
106
- # enabled). Infers where to send the output if used as a mixin.
107
- # DEPRECATED.
108
- def stagger_output(text, out = nil)
109
- Pry.new.pager.page text
110
- end
1
+ module Pry::Helpers; end
2
+
3
+ # rubocop:disable Metrics/ModuleLength
4
+ module Pry::Helpers::BaseHelpers
5
+ extend self
6
+
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
+ def silence_warnings
134
+ old_verbose = $VERBOSE
135
+ $VERBOSE = nil
136
+ begin
137
+ yield
138
+ ensure
139
+ $VERBOSE = old_verbose
140
+ end
141
+ end
142
+
143
+ # Acts like send but ignores any methods defined below Object or Class in the
144
+ # inheritance hierarchy.
145
+ # This is required to introspect methods on objects like Net::HTTP::Get that
146
+ # have overridden the `method` method.
147
+ def safe_send(obj, method, *args, &block)
148
+ (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
149
+ end
150
+ public :safe_send
151
+
152
+ def find_command(name, set = Pry::Commands)
153
+ command_match = set.find do |_, command|
154
+ (listing = command.options[:listing]) == name && listing != nil
155
+ end
156
+ command_match.last if command_match
157
+ end
158
+
159
+ def not_a_real_file?(file)
160
+ file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
161
+ end
162
+
163
+ def command_dependencies_met?(options)
164
+ return true if !options[:requires_gem]
165
+
166
+ Array(options[:requires_gem]).all? do |g|
167
+ Pry::Rubygem.installed?(g)
168
+ end
169
+ end
170
+
171
+ def use_ansi_codes?
172
+ Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
173
+ end
174
+
175
+ def colorize_code(code)
176
+ CodeRay.scan(code, :ruby).term
177
+ end
178
+
179
+ def highlight(string, regexp, highlight_color = :bright_yellow)
180
+ string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
181
+ end
182
+
183
+ # formatting
184
+ def heading(text)
185
+ text = "#{text}\n--"
186
+ "\e[1m#{text}\e[0m"
187
+ end
188
+
189
+ # Send the given text through the best available pager (if Pry.config.pager is
190
+ # enabled). Infers where to send the output if used as a mixin.
191
+ # DEPRECATED.
192
+ def stagger_output(text, _out = nil)
193
+ if defined?(_pry_) && _pry_
194
+ _pry_.pager.page text
195
+ else
196
+ Pry.new.pager.page text
111
197
  end
112
198
  end
113
199
  end
200
+ # rubocop:enable Metrics/ModuleLength
@@ -8,7 +8,7 @@ class Pry
8
8
 
9
9
  # Open a temp file and yield it to the block, closing it after
10
10
  # @return [String] The path of the temp file
11
- def temp_file(ext='.rb')
11
+ def temp_file(ext = '.rb')
12
12
  file = Tempfile.new(['pry', ext])
13
13
  yield file
14
14
  ensure
@@ -21,7 +21,7 @@ class Pry
21
21
  ["__binding__", "__pry__", "class_eval"].include?(m)
22
22
  end
23
23
 
24
- def get_method_or_raise(name, target, opts={}, omit_help=false)
24
+ def get_method_or_raise(name, target, opts = {}, omit_help = false)
25
25
  meth = Pry::Method.from_str(name, target, opts)
26
26
 
27
27
  if name && !meth
@@ -44,7 +44,7 @@ class Pry
44
44
  meth
45
45
  end
46
46
 
47
- def command_error(message, omit_help, klass=CommandError)
47
+ def command_error(message, omit_help, klass = CommandError)
48
48
  message += " Type `#{command_name} --help` for help." unless omit_help
49
49
  raise klass, message
50
50
  end
@@ -142,8 +142,9 @@ class Pry
142
142
  Range.new(a, b)
143
143
  end
144
144
 
145
- def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
145
+ def set_file_and_dir_locals(file_name, _pry_ = _pry_(), target = target())
146
146
  return if !target or !file_name
147
+
147
148
  _pry_.last_file = File.expand_path(file_name)
148
149
  _pry_.inject_local("_file_", _pry_.last_file, target)
149
150
 
@@ -12,8 +12,9 @@ class Pry
12
12
  comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, :ruby).term }.
13
13
  gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }.
14
14
  gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { "\e[1m#{$1}\e[0m" }.
15
- gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
16
- gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
15
+ gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan($1, :ruby).term }.
16
+ gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
17
+ gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
17
18
  gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan($1, :ruby).term}`" }
18
19
  end
19
20
 
@@ -3,13 +3,13 @@ class Pry
3
3
  module OptionsHelpers
4
4
  module_function
5
5
 
6
- # Add method options to the Slop instance
6
+ # Add method options to the Pry::Slop instance
7
7
  def method_options(opt)
8
8
  @method_target = target
9
9
  opt.on :M, "instance-methods", "Operate on instance methods."
10
10
  opt.on :m, :methods, "Operate on methods."
11
- opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors.", :as => :count
12
- opt.on :c, :context, "Select object context to run under.", :argument => true do |context|
11
+ opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors.", as: :count
12
+ opt.on :c, :context, "Select object context to run under.", argument: true do |context|
13
13
  @method_target = Pry.binding_for(target.eval(context))
14
14
  end
15
15
  end
@@ -17,9 +17,9 @@ class Pry
17
17
  # Get the method object parsed by the slop instance
18
18
  def method_object
19
19
  @method_object ||= get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target,
20
- :super => opts[:super],
21
- :instance => opts.present?(:'instance-methods') && !opts.present?(:'methods'),
22
- :methods => opts.present?(:'methods') && !opts.present?(:'instance-methods')
20
+ super: opts[:super],
21
+ instance: opts.present?(:'instance-methods') && !opts.present?(:'methods'),
22
+ methods: opts.present?(:'methods') && !opts.present?(:'instance-methods')
23
23
  )
24
24
  end
25
25
  end
@@ -0,0 +1,58 @@
1
+ class Pry
2
+ module Helpers
3
+ # Contains methods for querying the platform that Pry is running on
4
+ # @api public
5
+ # @since v0.12.0
6
+ # rubocop:disable Style/DoubleNegation
7
+ module Platform
8
+ # @return [Boolean]
9
+ def self.mac_osx?
10
+ !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
11
+ end
12
+
13
+ # @return [Boolean]
14
+ def self.linux?
15
+ !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
16
+ end
17
+
18
+ # @return [Boolean] true when Pry is running on Windows with ANSI support,
19
+ # false otherwise
20
+ def self.windows?
21
+ !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
22
+ end
23
+
24
+ # @return [Boolean]
25
+ def self.windows_ansi?
26
+ return false unless windows?
27
+
28
+ !!(defined?(Win32::Console) || ENV['ANSICON'] || mri_2?)
29
+ end
30
+
31
+ # @return [Boolean]
32
+ def self.jruby?
33
+ RbConfig::CONFIG['ruby_install_name'] == 'jruby'
34
+ end
35
+
36
+ # @return [Boolean]
37
+ def self.jruby_19?
38
+ jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
39
+ end
40
+
41
+ # @return [Boolean]
42
+ def self.mri?
43
+ RbConfig::CONFIG['ruby_install_name'] == 'ruby'
44
+ end
45
+
46
+ # @return [Boolean]
47
+ def self.mri_19?
48
+ !!(mri? && RUBY_VERSION.start_with?('1.9'))
49
+ end
50
+
51
+ # @return [Boolean]
52
+ def self.mri_2?
53
+ !!(mri? && RUBY_VERSION.start_with?('2'))
54
+ end
55
+ end
56
+ # rubocop:enable Style/DoubleNegation
57
+ end
58
+ end
@@ -1,27 +1,28 @@
1
1
  class Pry
2
2
  module Helpers
3
- def self.tablify_or_one_line(heading, things)
3
+ def self.tablify_or_one_line(heading, things, config = Pry.config)
4
4
  plain_heading = Pry::Helpers::Text.strip_color(heading)
5
- attempt = Table.new(things, :column_count => things.size)
5
+ attempt = Table.new(things, column_count: things.size)
6
6
  if attempt.fits_on_line?(Terminal.width! - plain_heading.size - 2)
7
7
  "#{heading}: #{attempt}\n"
8
8
  else
9
- "#{heading}: \n#{tablify_to_screen_width(things, :indent => ' ')}\n"
9
+ "#{heading}: \n#{tablify_to_screen_width(things, { indent: ' ' }, config)}\n"
10
10
  end
11
11
  end
12
12
 
13
- def self.tablify_to_screen_width(things, options = {})
13
+ def self.tablify_to_screen_width(things, options, config = Pry.config)
14
+ options ||= {}
14
15
  things = things.compact
15
- if indent = options[:indent]
16
+ if (indent = options[:indent])
16
17
  usable_width = Terminal.width! - indent.size
17
- tablify(things, usable_width).to_s.gsub(/^/, indent)
18
+ tablify(things, usable_width, config).to_s.gsub(/^/, indent)
18
19
  else
19
- tablify(things, Terminal.width!).to_s
20
+ tablify(things, Terminal.width!, config).to_s
20
21
  end
21
22
  end
22
23
 
23
- def self.tablify(things, line_length)
24
- table = Table.new(things, :column_count => things.size)
24
+ def self.tablify(things, line_length, config = Pry.config)
25
+ table = Table.new(things, { column_count: things.size }, config)
25
26
  table.column_count -= 1 until 1 == table.column_count or
26
27
  table.fits_on_line?(line_length)
27
28
  table
@@ -29,8 +30,9 @@ class Pry
29
30
 
30
31
  class Table
31
32
  attr_reader :items, :column_count
32
- def initialize items, args = {}
33
+ def initialize(items, args, config = Pry.config)
33
34
  @column_count = args[:column_count]
35
+ @config = config
34
36
  self.items = items
35
37
  end
36
38
 
@@ -39,16 +41,17 @@ class Pry
39
41
  end
40
42
 
41
43
  def rows_to_s style = :color_on
42
- widths = columns.map{|e| _max_width(e)}
44
+ widths = columns.map { |e| _max_width(e) }
43
45
  @rows_without_colors.map do |r|
44
46
  padded = []
45
47
  r.each_with_index do |e,i|
46
48
  next unless e
49
+
47
50
  item = e.ljust(widths[i])
48
51
  item.sub! e, _recall_color_for(e) if :color_on == style
49
52
  padded << item
50
53
  end
51
- padded.join(Pry.config.ls.separator)
54
+ padded.join(@config.ls.separator)
52
55
  end
53
56
  end
54
57
 
@@ -73,6 +76,7 @@ class Pry
73
76
  end
74
77
 
75
78
  def ==(other); items == other.to_a end
79
+
76
80
  def to_a; items.to_a end
77
81
 
78
82
  private
@@ -93,10 +97,11 @@ class Pry
93
97
  def _recolumn
94
98
  @rows_without_colors = []
95
99
  return if items.size.zero?
96
- row_count = (items.size.to_f/column_count).ceil
100
+
101
+ row_count = (items.size.to_f / column_count).ceil
97
102
  row_count.times do |i|
98
- row_indices = (0...column_count).map{|e| row_count*e+i}
99
- @rows_without_colors << row_indices.map{|e| @plain_items[e]}
103
+ row_indices = (0...column_count).map { |e| row_count * e + i }
104
+ @rows_without_colors << row_indices.map { |e| @plain_items[e] }
100
105
  end
101
106
  end
102
107