pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +122 -183
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/completion.rb +0 -221
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -15,53 +15,29 @@ class Pry
|
|
15
15
|
file.close(true) if file
|
16
16
|
end
|
17
17
|
|
18
|
-
def render_output(str, opts={})
|
19
|
-
if opts[:flood]
|
20
|
-
output.puts str
|
21
|
-
else
|
22
|
-
stagger_output str
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Return the file and line for a Binding.
|
27
|
-
# @param [Binding] target The binding
|
28
|
-
# @return [Array] The file and line
|
29
|
-
def file_and_line_from_binding(target)
|
30
|
-
file = target.eval('__FILE__')
|
31
|
-
line_num = target.eval('__LINE__')
|
32
|
-
if rbx?
|
33
|
-
if !target.instance_variable_defined?(:@__actual_file__)
|
34
|
-
target.instance_variable_set(:@__actual_file__, RbxPath.convert_path_to_full(target.variables.method.file.to_s))
|
35
|
-
end
|
36
|
-
file = target.instance_variable_get(:@__actual_file__).to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
[file, line_num]
|
40
|
-
end
|
41
|
-
|
42
18
|
def internal_binding?(target)
|
43
|
-
m = target.eval("__method__").to_s
|
19
|
+
m = target.eval("::Kernel.__method__").to_s
|
44
20
|
# class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
|
45
|
-
["__binding__", "
|
21
|
+
["__binding__", "__pry__", "class_eval"].include?(m)
|
46
22
|
end
|
47
23
|
|
48
24
|
def get_method_or_raise(name, target, opts={}, omit_help=false)
|
49
25
|
meth = Pry::Method.from_str(name, target, opts)
|
50
26
|
|
51
27
|
if name && !meth
|
52
|
-
command_error("The method '#{name}' could not be found.", omit_help)
|
28
|
+
command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
|
53
29
|
end
|
54
30
|
|
55
31
|
(opts[:super] || 0).times do
|
56
32
|
if meth.super
|
57
33
|
meth = meth.super
|
58
34
|
else
|
59
|
-
command_error("'#{meth.name_with_owner}' has no super method.", omit_help)
|
35
|
+
command_error("'#{meth.name_with_owner}' has no super method.", omit_help, MethodNotFound)
|
60
36
|
end
|
61
37
|
end
|
62
38
|
|
63
39
|
if !meth || (!name && internal_binding?(target))
|
64
|
-
command_error("No method name given, and context is not a method.", omit_help,
|
40
|
+
command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
|
65
41
|
end
|
66
42
|
|
67
43
|
set_file_and_dir_locals(meth.source_file)
|
@@ -73,104 +49,6 @@ class Pry
|
|
73
49
|
raise klass, message
|
74
50
|
end
|
75
51
|
|
76
|
-
def make_header(meth, content=meth.source)
|
77
|
-
header = "\n#{Pry::Helpers::Text.bold('From:')} #{meth.source_file} "
|
78
|
-
|
79
|
-
if meth.source_type == :c
|
80
|
-
header << "(C Method):\n"
|
81
|
-
else
|
82
|
-
header << "@ line #{meth.source_line}:\n"
|
83
|
-
end
|
84
|
-
|
85
|
-
header << "#{Pry::Helpers::Text.bold("Number of lines:")} #{content.each_line.count.to_s}\n"
|
86
|
-
end
|
87
|
-
|
88
|
-
def invoke_editor(file, line, reloading)
|
89
|
-
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless Pry.config.editor
|
90
|
-
if Pry.config.editor.respond_to?(:call)
|
91
|
-
args = [file, line, reloading][0...(Pry.config.editor.arity)]
|
92
|
-
editor_invocation = Pry.config.editor.call(*args)
|
93
|
-
else
|
94
|
-
editor_invocation = "#{Pry.config.editor} #{blocking_flag_for_editor(reloading)} #{start_line_syntax_for_editor(file, line)}"
|
95
|
-
end
|
96
|
-
return nil unless editor_invocation
|
97
|
-
|
98
|
-
if jruby?
|
99
|
-
begin
|
100
|
-
require 'spoon'
|
101
|
-
pid = Spoon.spawnp(*editor_invocation.split)
|
102
|
-
Process.waitpid(pid)
|
103
|
-
rescue FFI::NotFoundError
|
104
|
-
system(editor_invocation)
|
105
|
-
end
|
106
|
-
else
|
107
|
-
# Note we dont want to use Pry.config.system here as that
|
108
|
-
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
109
|
-
# ensure the editor is always interactive
|
110
|
-
system(editor_invocation) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Some editors that run outside the terminal allow you to control whether or
|
115
|
-
# not to block the process from which they were launched (in this case, Pry).
|
116
|
-
# For those editors, return the flag that produces the desired behavior.
|
117
|
-
def blocking_flag_for_editor(block)
|
118
|
-
case editor_name
|
119
|
-
when /^emacsclient/
|
120
|
-
'--no-wait' unless block
|
121
|
-
when /^[gm]vim/
|
122
|
-
'--nofork' if block
|
123
|
-
when /^jedit/
|
124
|
-
'-wait' if block
|
125
|
-
when /^mate/, /^subl/
|
126
|
-
'-w' if block
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# Return the syntax for a given editor for starting the editor
|
131
|
-
# and moving to a particular line within that file
|
132
|
-
def start_line_syntax_for_editor(file_name, line_number)
|
133
|
-
if windows?
|
134
|
-
file_name = file_name.gsub(/\//, '\\')
|
135
|
-
end
|
136
|
-
|
137
|
-
# special case for 1st line
|
138
|
-
return file_name if line_number <= 1
|
139
|
-
|
140
|
-
case editor_name
|
141
|
-
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
142
|
-
"+#{line_number} #{file_name}"
|
143
|
-
when /^mate/, /^geany/
|
144
|
-
"-l #{line_number} #{file_name}"
|
145
|
-
when /^subl/
|
146
|
-
"#{file_name}:#{line_number}"
|
147
|
-
when /^uedit32/
|
148
|
-
"#{file_name}/#{line_number}"
|
149
|
-
when /^jedit/
|
150
|
-
"#{file_name} +line:#{line_number}"
|
151
|
-
else
|
152
|
-
if windows?
|
153
|
-
"#{file_name}"
|
154
|
-
else
|
155
|
-
"+#{line_number} #{file_name}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Get the name of the binary that Pry.config.editor points to.
|
161
|
-
#
|
162
|
-
# This is useful for deciding which flags we pass to the editor as
|
163
|
-
# we can just use the program's name and ignore any absolute paths.
|
164
|
-
#
|
165
|
-
# @example
|
166
|
-
# Pry.config.editor="/home/conrad/bin/textmate -w"
|
167
|
-
# editor_name
|
168
|
-
# # => textmate
|
169
|
-
#
|
170
|
-
def editor_name
|
171
|
-
File.basename(Pry.config.editor).split(" ").first
|
172
|
-
end
|
173
|
-
|
174
52
|
# Remove any common leading whitespace from every line in `text`.
|
175
53
|
#
|
176
54
|
# This can be used to make a HEREDOC line up with the left margin, without
|
@@ -193,12 +71,14 @@ class Pry
|
|
193
71
|
#
|
194
72
|
# @param [String] text The text from which to remove indentation
|
195
73
|
# @return [String] The text with indentation stripped.
|
196
|
-
def unindent(text)
|
74
|
+
def unindent(text, left_padding = 0)
|
197
75
|
# Empty blank lines
|
198
76
|
text = text.sub(/^[ \t]+$/, '')
|
199
77
|
|
200
78
|
# Find the longest common whitespace to all indented lines
|
201
|
-
|
79
|
+
# Ignore lines containing just -- or ++ as these seem to be used by
|
80
|
+
# comment authors as delimeters.
|
81
|
+
margin = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/).inject do |current_margin, next_indent|
|
202
82
|
if next_indent.start_with?(current_margin)
|
203
83
|
current_margin
|
204
84
|
elsif current_margin.start_with?(next_indent)
|
@@ -208,7 +88,7 @@ class Pry
|
|
208
88
|
end
|
209
89
|
end
|
210
90
|
|
211
|
-
text.gsub(/^#{margin}/, '')
|
91
|
+
text.gsub(/^#{margin}/, ' ' * left_padding)
|
212
92
|
end
|
213
93
|
|
214
94
|
# Restrict a string to the given range of lines (1-indexed)
|
@@ -261,6 +141,15 @@ class Pry
|
|
261
141
|
|
262
142
|
Range.new(a, b)
|
263
143
|
end
|
144
|
+
|
145
|
+
def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
|
146
|
+
return if !target or !file_name
|
147
|
+
_pry_.last_file = File.expand_path(file_name)
|
148
|
+
_pry_.inject_local("_file_", _pry_.last_file, target)
|
149
|
+
|
150
|
+
_pry_.last_dir = File.dirname(_pry_.last_file)
|
151
|
+
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
152
|
+
end
|
264
153
|
end
|
265
154
|
|
266
155
|
end
|
@@ -4,14 +4,17 @@ class Pry
|
|
4
4
|
# This class contains methods useful for extracting
|
5
5
|
# documentation from methods and classes.
|
6
6
|
module DocumentationHelpers
|
7
|
-
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def process_rdoc(comment)
|
8
11
|
comment = comment.dup
|
9
|
-
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) {
|
10
|
-
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) {
|
11
|
-
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) {
|
12
|
-
gsub(/\B\+(\w
|
13
|
-
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) {
|
14
|
-
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{
|
12
|
+
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, :ruby).term }.
|
13
|
+
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }.
|
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 }.
|
17
|
+
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan($1, :ruby).term}`" }
|
15
18
|
end
|
16
19
|
|
17
20
|
def process_yardoc_tag(comment, tag)
|
@@ -33,11 +36,11 @@ class Pry
|
|
33
36
|
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
|
34
37
|
"deprecate", "example", "raise"]
|
35
38
|
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
|
36
|
-
gsub(/^@(#{yard_tags.join("|")})/) {
|
39
|
+
gsub(/^@(#{yard_tags.join("|")})/) { "\e[33m#{$1}\e[0m" }
|
37
40
|
end
|
38
41
|
|
39
|
-
def process_comment_markup(comment
|
40
|
-
process_yardoc process_rdoc(comment
|
42
|
+
def process_comment_markup(comment)
|
43
|
+
process_yardoc process_rdoc(comment)
|
41
44
|
end
|
42
45
|
|
43
46
|
# @param [String] code
|
@@ -46,10 +49,17 @@ class Pry
|
|
46
49
|
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
|
47
50
|
end
|
48
51
|
|
52
|
+
# Given a string that makes up a comment in a source-code file parse out the content
|
53
|
+
# that the user is intended to read. (i.e. without leading indentation, #-characters
|
54
|
+
# or shebangs)
|
55
|
+
#
|
49
56
|
# @param [String] comment
|
50
57
|
# @return [String]
|
51
|
-
def
|
58
|
+
def get_comment_content(comment)
|
52
59
|
comment = comment.dup
|
60
|
+
# Remove #!/usr/bin/ruby
|
61
|
+
comment.gsub!(/\A\#!.*$/, '')
|
62
|
+
# Remove leading empty comment lines
|
53
63
|
comment.gsub!(/\A\#+?$/, '')
|
54
64
|
comment.gsub!(/^\s*#/, '')
|
55
65
|
strip_leading_whitespace(comment)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
class Pry
|
2
|
+
module Helpers
|
3
|
+
def self.tablify_or_one_line(heading, things)
|
4
|
+
plain_heading = Pry::Helpers::Text.strip_color(heading)
|
5
|
+
attempt = Table.new(things, :column_count => things.size)
|
6
|
+
if attempt.fits_on_line?(Terminal.width! - plain_heading.size - 2)
|
7
|
+
"#{heading}: #{attempt}\n"
|
8
|
+
else
|
9
|
+
"#{heading}: \n#{tablify_to_screen_width(things, :indent => ' ')}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.tablify_to_screen_width(things, options = {})
|
14
|
+
things = things.compact
|
15
|
+
if indent = options[:indent]
|
16
|
+
usable_width = Terminal.width! - indent.size
|
17
|
+
tablify(things, usable_width).to_s.gsub(/^/, indent)
|
18
|
+
else
|
19
|
+
tablify(things, Terminal.width!).to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.tablify(things, line_length)
|
24
|
+
table = Table.new(things, :column_count => things.size)
|
25
|
+
table.column_count -= 1 until 1 == table.column_count or
|
26
|
+
table.fits_on_line?(line_length)
|
27
|
+
table
|
28
|
+
end
|
29
|
+
|
30
|
+
class Table
|
31
|
+
attr_reader :items, :column_count
|
32
|
+
def initialize items, args = {}
|
33
|
+
@column_count = args[:column_count]
|
34
|
+
self.items = items
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
rows_to_s.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
def rows_to_s style = :color_on
|
42
|
+
widths = columns.map{|e| _max_width(e)}
|
43
|
+
@rows_without_colors.map do |r|
|
44
|
+
padded = []
|
45
|
+
r.each_with_index do |e,i|
|
46
|
+
next unless e
|
47
|
+
item = e.ljust(widths[i])
|
48
|
+
item.sub! e, _recall_color_for(e) if :color_on == style
|
49
|
+
padded << item
|
50
|
+
end
|
51
|
+
padded.join(Pry.config.ls.separator)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def items= items
|
56
|
+
@items = items
|
57
|
+
_rebuild_colorless_cache
|
58
|
+
_recolumn
|
59
|
+
items
|
60
|
+
end
|
61
|
+
|
62
|
+
def column_count= n
|
63
|
+
@column_count = n
|
64
|
+
_recolumn
|
65
|
+
end
|
66
|
+
|
67
|
+
def fits_on_line? line_length
|
68
|
+
_max_width(rows_to_s :no_color) <= line_length
|
69
|
+
end
|
70
|
+
|
71
|
+
def columns
|
72
|
+
@rows_without_colors.transpose
|
73
|
+
end
|
74
|
+
|
75
|
+
def ==(other); items == other.to_a end
|
76
|
+
def to_a; items.to_a end
|
77
|
+
|
78
|
+
private
|
79
|
+
def _max_width(things)
|
80
|
+
things.compact.map(&:size).max || 0
|
81
|
+
end
|
82
|
+
|
83
|
+
def _rebuild_colorless_cache
|
84
|
+
@colorless_cache = {}
|
85
|
+
@plain_items = []
|
86
|
+
items.map do |e|
|
87
|
+
plain = Pry::Helpers::Text.strip_color(e)
|
88
|
+
@colorless_cache[plain] = e
|
89
|
+
@plain_items << plain
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def _recolumn
|
94
|
+
@rows_without_colors = []
|
95
|
+
return if items.size.zero?
|
96
|
+
row_count = (items.size.to_f/column_count).ceil
|
97
|
+
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]}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def _recall_color_for thing
|
104
|
+
@colorless_cache[thing]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
data/lib/pry/helpers/text.rb
CHANGED
@@ -21,11 +21,11 @@ class Pry
|
|
21
21
|
|
22
22
|
COLORS.each_pair do |color, value|
|
23
23
|
define_method color do |text|
|
24
|
-
|
24
|
+
"\033[0;#{30+value}m#{text}\033[0m"
|
25
25
|
end
|
26
26
|
|
27
27
|
define_method "bright_#{color}" do |text|
|
28
|
-
|
28
|
+
"\033[1;#{30+value}m#{text}\033[0m"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,17 +33,16 @@ class Pry
|
|
33
33
|
#
|
34
34
|
# @param [String, #to_s] text
|
35
35
|
# @return [String] _text_ stripped of any color codes.
|
36
|
-
def strip_color
|
36
|
+
def strip_color(text)
|
37
37
|
text.to_s.gsub(/\e\[.*?(\d)+m/ , '')
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns _text_ as bold text for use on a terminal.
|
41
|
-
# _Pry.color_ must be true for this method to perform any transformations.
|
42
41
|
#
|
43
42
|
# @param [String, #to_s] text
|
44
43
|
# @return [String] _text_
|
45
|
-
def bold
|
46
|
-
|
44
|
+
def bold(text)
|
45
|
+
"\e[1m#{text}\e[0m"
|
47
46
|
end
|
48
47
|
|
49
48
|
# Returns `text` in the default foreground colour.
|
@@ -56,10 +55,10 @@ class Pry
|
|
56
55
|
end
|
57
56
|
alias_method :bright_default, :bold
|
58
57
|
|
59
|
-
# Executes the block with `Pry.color` set to false.
|
58
|
+
# Executes the block with `Pry.config.color` set to false.
|
60
59
|
# @yield
|
61
60
|
# @return [void]
|
62
|
-
def no_color
|
61
|
+
def no_color(&block)
|
63
62
|
boolean = Pry.config.color
|
64
63
|
Pry.config.color = false
|
65
64
|
yield
|
@@ -70,7 +69,7 @@ class Pry
|
|
70
69
|
# Executes the block with `Pry.config.pager` set to false.
|
71
70
|
# @yield
|
72
71
|
# @return [void]
|
73
|
-
def no_pager
|
72
|
+
def no_pager(&block)
|
74
73
|
boolean = Pry.config.pager
|
75
74
|
Pry.config.pager = false
|
76
75
|
yield
|
data/lib/pry/history.rb
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
class Pry
|
2
|
-
# The History class is responsible for maintaining the user's input history,
|
3
|
-
# internally and within Readline.
|
2
|
+
# The History class is responsible for maintaining the user's input history,
|
3
|
+
# both internally and within Readline.
|
4
4
|
class History
|
5
5
|
attr_accessor :loader, :saver, :pusher, :clearer
|
6
6
|
|
7
|
-
|
7
|
+
# @return [Fixnum] Number of lines in history when Pry first loaded.
|
8
|
+
attr_reader :original_lines
|
9
|
+
|
10
|
+
def initialize(options={})
|
8
11
|
@history = []
|
9
|
-
@
|
12
|
+
@original_lines = 0
|
13
|
+
@file_path = options[:file_path]
|
10
14
|
restore_default_behavior
|
11
15
|
end
|
12
16
|
|
13
17
|
# Assign the default methods for loading, saving, pushing, and clearing.
|
14
18
|
def restore_default_behavior
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
@
|
19
|
+
Pry.config.input # force Readline to load if applicable
|
20
|
+
|
21
|
+
@loader = method(:read_from_file)
|
22
|
+
@saver = method(:save_to_file)
|
23
|
+
|
24
|
+
if defined?(Readline)
|
25
|
+
@pusher = method(:push_to_readline)
|
26
|
+
@clearer = method(:clear_readline)
|
27
|
+
else
|
28
|
+
@pusher = proc { }
|
29
|
+
@clearer = proc { }
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
# Load the input history using `History.loader`.
|
@@ -24,17 +36,8 @@ class Pry
|
|
24
36
|
@loader.call do |line|
|
25
37
|
@pusher.call(line.chomp)
|
26
38
|
@history << line.chomp
|
39
|
+
@original_lines += 1
|
27
40
|
end
|
28
|
-
@saved_lines = @history.length
|
29
|
-
end
|
30
|
-
|
31
|
-
# Write this session's history using `History.saver`.
|
32
|
-
# @return [Integer] The number of lines saved
|
33
|
-
def save
|
34
|
-
history_to_save = @history[@saved_lines..-1]
|
35
|
-
@saver.call(history_to_save)
|
36
|
-
@saved_lines = @history.length
|
37
|
-
history_to_save.length
|
38
41
|
end
|
39
42
|
|
40
43
|
# Add a line to the input history, ignoring blank and duplicate lines.
|
@@ -44,18 +47,27 @@ class Pry
|
|
44
47
|
unless line.empty? || (@history.last && line == @history.last)
|
45
48
|
@pusher.call(line)
|
46
49
|
@history << line
|
50
|
+
@saver.call(line) if Pry.config.history.should_save
|
47
51
|
end
|
48
52
|
line
|
49
53
|
end
|
50
54
|
alias << push
|
51
55
|
|
52
|
-
# Clear
|
53
|
-
#
|
54
|
-
# history file on exit.
|
56
|
+
# Clear this session's history. This won't affect the contents of the
|
57
|
+
# history file.
|
55
58
|
def clear
|
56
59
|
@clearer.call
|
57
60
|
@history = []
|
58
|
-
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Fixnum] The number of lines in history.
|
64
|
+
def history_line_count
|
65
|
+
@history.count
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [Fixnum] The number of lines in history from just this session.
|
69
|
+
def session_line_count
|
70
|
+
@history.count - @original_lines
|
59
71
|
end
|
60
72
|
|
61
73
|
# Return an Array containing all stored history.
|
@@ -66,33 +78,16 @@ class Pry
|
|
66
78
|
end
|
67
79
|
|
68
80
|
private
|
81
|
+
|
69
82
|
# The default loader. Yields lines from `Pry.history.config.file`.
|
70
83
|
def read_from_file
|
71
|
-
|
72
|
-
history_file = File.expand_path(Pry.config.history.file)
|
73
|
-
if File.exists?(history_file)
|
74
|
-
File.foreach(history_file) { |line| yield(line) }
|
75
|
-
end
|
76
|
-
rescue => error
|
77
|
-
unless error.message.empty?
|
78
|
-
warn "History file not loaded, received an error: #{error.message}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
84
|
+
filename = File.expand_path(Pry.config.history.file)
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
def write_to_file(lines)
|
86
|
-
history_file = File.expand_path(Pry.config.history.file)
|
87
|
-
|
88
|
-
begin
|
89
|
-
File.open(history_file, 'a') do |f|
|
90
|
-
lines.each { |ln| f.puts ln }
|
91
|
-
end
|
92
|
-
rescue Errno::EACCES
|
93
|
-
# We should probably create an option Pry.show_warnings?!?!?!
|
94
|
-
warn 'Unable to write to your history file, history not saved'
|
86
|
+
if File.exists?(filename)
|
87
|
+
File.foreach(filename) { |line| yield(line) }
|
95
88
|
end
|
89
|
+
rescue => error
|
90
|
+
warn "History file not loaded: #{error.message}"
|
96
91
|
end
|
97
92
|
|
98
93
|
# The default pusher. Appends the given line to Readline::HISTORY.
|
@@ -105,5 +100,26 @@ class Pry
|
|
105
100
|
def clear_readline
|
106
101
|
Readline::HISTORY.shift until Readline::HISTORY.empty?
|
107
102
|
end
|
103
|
+
|
104
|
+
# The default saver. Appends the given line to `Pry.history.config.file`.
|
105
|
+
def save_to_file(line)
|
106
|
+
history_file.puts line if history_file
|
107
|
+
end
|
108
|
+
|
109
|
+
# The history file, opened for appending.
|
110
|
+
def history_file
|
111
|
+
if defined?(@history_file)
|
112
|
+
@history_file
|
113
|
+
else
|
114
|
+
@history_file = File.open(file_path, 'a', 0600).tap { |f| f.sync = true }
|
115
|
+
end
|
116
|
+
rescue Errno::EACCES
|
117
|
+
warn 'History not saved; unable to open your history file for writing.'
|
118
|
+
@history_file = false
|
119
|
+
end
|
120
|
+
|
121
|
+
def file_path
|
122
|
+
@file_path || Pry.config.history.file
|
123
|
+
end
|
108
124
|
end
|
109
125
|
end
|