pry 0.11.3 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +139 -1
- data/LICENSE +1 -1
- data/README.md +13 -30
- data/bin/pry +0 -4
- data/lib/pry.rb +17 -47
- data/lib/pry/cli.rb +17 -24
- data/lib/pry/code.rb +6 -6
- data/lib/pry/code/code_file.rb +5 -4
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code_object.rb +4 -4
- data/lib/pry/color_printer.rb +1 -0
- data/lib/pry/command.rb +36 -29
- data/lib/pry/command_set.rb +17 -52
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/cat/exception_formatter.rb +9 -8
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +9 -9
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +8 -7
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +11 -13
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gem_search.rb +2 -2
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +9 -8
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls.rb +27 -30
- data/lib/pry/commands/ls/constants.rb +4 -4
- data/lib/pry/commands/ls/formatter.rb +3 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +0 -1
- data/lib/pry/commands/play.rb +1 -2
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/ri.rb +5 -4
- data/lib/pry/commands/shell_command.rb +3 -2
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +25 -18
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +4 -4
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config.rb +33 -9
- data/lib/pry/config/behavior.rb +229 -205
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +153 -143
- data/lib/pry/config/memoization.rb +41 -37
- data/lib/pry/core_extensions.rb +4 -3
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +0 -2
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +133 -4
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +2 -2
- data/lib/pry/helpers/options_helpers.rb +5 -5
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +3 -4
- data/lib/pry/history.rb +21 -8
- data/lib/pry/hooks.rb +3 -3
- data/lib/pry/indent.rb +15 -17
- data/lib/pry/input_completer.rb +12 -7
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +1 -1
- data/lib/pry/method.rb +37 -31
- data/lib/pry/method/disowned.rb +2 -1
- data/lib/pry/method/patcher.rb +2 -2
- data/lib/pry/method/weird_method_locator.rb +7 -8
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +3 -2
- data/lib/pry/pager.rb +4 -3
- data/lib/pry/platform.rb +79 -81
- data/lib/pry/plugins.rb +7 -3
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +53 -29
- data/lib/pry/pry_instance.rb +88 -55
- data/lib/pry/repl.rb +33 -4
- data/lib/pry/repl_file_loader.rb +1 -2
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +6 -6
- data/lib/pry/slop.rb +17 -17
- data/lib/pry/slop/commands.rb +3 -4
- data/lib/pry/slop/option.rb +19 -21
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/testable/mockable.rb +2 -2
- data/lib/pry/testable/pry_tester.rb +1 -1
- data/lib/pry/testable/utility.rb +2 -2
- data/lib/pry/testable/variables.rb +1 -1
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +15 -15
- data/lib/pry/wrapped_module/candidate.rb +2 -2
- metadata +17 -29
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
data/lib/pry/editor.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class Pry
|
2
2
|
class Editor
|
3
|
-
include Pry::Helpers::BaseHelpers
|
4
3
|
include Pry::Helpers::CommandHelpers
|
5
4
|
|
6
5
|
attr_reader :_pry_
|
@@ -9,7 +8,7 @@ class Pry
|
|
9
8
|
@_pry_ = _pry_
|
10
9
|
end
|
11
10
|
|
12
|
-
def edit_tempfile_with_content(initial_content, line=1)
|
11
|
+
def edit_tempfile_with_content(initial_content, line = 1)
|
13
12
|
temp_file do |f|
|
14
13
|
f.puts(initial_content)
|
15
14
|
f.flush
|
@@ -19,13 +18,13 @@ class Pry
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
def invoke_editor(file, line, blocking=true)
|
21
|
+
def invoke_editor(file, line, blocking = true)
|
23
22
|
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor
|
24
23
|
|
25
24
|
editor_invocation = build_editor_invocation_string(file, line, blocking)
|
26
25
|
return nil unless editor_invocation
|
27
26
|
|
28
|
-
if jruby?
|
27
|
+
if Helpers::Platform.jruby?
|
29
28
|
open_editor_on_jruby(editor_invocation)
|
30
29
|
else
|
31
30
|
open_editor(editor_invocation)
|
@@ -43,12 +42,7 @@ class Pry
|
|
43
42
|
args = [file, line, blocking][0...(_pry_.config.editor.arity)]
|
44
43
|
_pry_.config.editor.call(*args)
|
45
44
|
else
|
46
|
-
sanitized_file =
|
47
|
-
file
|
48
|
-
else
|
49
|
-
Shellwords.escape(file)
|
50
|
-
end
|
51
|
-
|
45
|
+
sanitized_file = Helpers::Platform.windows? ? file : Shellwords.escape(file)
|
52
46
|
"#{_pry_.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
|
53
47
|
end
|
54
48
|
end
|
@@ -109,7 +103,7 @@ class Pry
|
|
109
103
|
when /^redcar/
|
110
104
|
"-l#{line_number} #{file_name}"
|
111
105
|
else
|
112
|
-
if windows?
|
106
|
+
if Helpers::Platform.windows?
|
113
107
|
"#{file_name}"
|
114
108
|
else
|
115
109
|
"+#{line_number} #{file_name}"
|
@@ -130,6 +124,5 @@ class Pry
|
|
130
124
|
def editor_name
|
131
125
|
File.basename(_pry_.config.editor).split(" ").first
|
132
126
|
end
|
133
|
-
|
134
127
|
end
|
135
128
|
end
|
data/lib/pry/exceptions.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class Pry
|
2
|
-
|
3
2
|
# As a REPL, we often want to catch any unexpected exceptions that may have
|
4
3
|
# been raised; however we don't want to go overboard and prevent the user
|
5
4
|
# from exiting Pry when they want to.
|
@@ -74,5 +73,4 @@ class Pry
|
|
74
73
|
# IRB = Pry thing.
|
75
74
|
module ExtendCommandBundle
|
76
75
|
end
|
77
|
-
|
78
76
|
end
|
data/lib/pry/helpers.rb
CHANGED
@@ -1,8 +1,135 @@
|
|
1
1
|
module Pry::Helpers; end
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/ModuleLength
|
2
4
|
module Pry::Helpers::BaseHelpers
|
3
|
-
include Pry::Platform
|
4
5
|
extend self
|
5
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
|
+
|
6
133
|
def silence_warnings
|
7
134
|
old_verbose = $VERBOSE
|
8
135
|
$VERBOSE = nil
|
@@ -35,20 +162,21 @@ module Pry::Helpers::BaseHelpers
|
|
35
162
|
|
36
163
|
def command_dependencies_met?(options)
|
37
164
|
return true if !options[:requires_gem]
|
165
|
+
|
38
166
|
Array(options[:requires_gem]).all? do |g|
|
39
167
|
Pry::Rubygem.installed?(g)
|
40
168
|
end
|
41
169
|
end
|
42
170
|
|
43
171
|
def use_ansi_codes?
|
44
|
-
windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
172
|
+
Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
45
173
|
end
|
46
174
|
|
47
175
|
def colorize_code(code)
|
48
176
|
CodeRay.scan(code, :ruby).term
|
49
177
|
end
|
50
178
|
|
51
|
-
def highlight(string, regexp, highlight_color
|
179
|
+
def highlight(string, regexp, highlight_color = :bright_yellow)
|
52
180
|
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
53
181
|
end
|
54
182
|
|
@@ -61,7 +189,7 @@ module Pry::Helpers::BaseHelpers
|
|
61
189
|
# Send the given text through the best available pager (if Pry.config.pager is
|
62
190
|
# enabled). Infers where to send the output if used as a mixin.
|
63
191
|
# DEPRECATED.
|
64
|
-
def stagger_output(text,
|
192
|
+
def stagger_output(text, _out = nil)
|
65
193
|
if defined?(_pry_) && _pry_
|
66
194
|
_pry_.pager.page text
|
67
195
|
else
|
@@ -69,3 +197,4 @@ module Pry::Helpers::BaseHelpers
|
|
69
197
|
end
|
70
198
|
end
|
71
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
|
|
@@ -13,8 +13,8 @@ class Pry
|
|
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
15
|
gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan($1, :ruby).term }.
|
16
|
-
gsub(/\B\+(\w+?)\+\B/)
|
17
|
-
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/)
|
16
|
+
gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
|
17
|
+
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
|
18
18
|
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan($1, :ruby).term}`" }
|
19
19
|
end
|
20
20
|
|
@@ -8,8 +8,8 @@ class Pry
|
|
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.", :
|
12
|
-
opt.on :c, :context, "Select object context to run under.", :
|
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
|
-
:
|
21
|
-
:
|
22
|
-
:
|
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
|
data/lib/pry/helpers/table.rb
CHANGED
@@ -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, :
|
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, :
|
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
|
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, :
|
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
|
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(
|
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
|
-
|
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
|
|