pry 0.10.pre.1-java → 0.10.0.pre2-java
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 +126 -182
- 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
@@ -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
|
data/lib/pry/history_array.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Pry
|
2
2
|
# A history array is an array to which you can only add elements. Older
|
3
|
-
# entries are removed progressively, so that the
|
3
|
+
# entries are removed progressively, so that the array never contains more than
|
4
4
|
# N elements.
|
5
5
|
#
|
6
6
|
# History arrays are used by Pry to store the output of the last commands.
|
@@ -89,6 +89,16 @@ class Pry
|
|
89
89
|
((@count - size)...@count).map { |n| @hash[n] }
|
90
90
|
end
|
91
91
|
|
92
|
+
# Returns [Hash] copy of the internal @hash history
|
93
|
+
def to_h
|
94
|
+
@hash.dup
|
95
|
+
end
|
96
|
+
|
97
|
+
def pop!
|
98
|
+
@hash.delete @count - 1
|
99
|
+
@count -= 1
|
100
|
+
end
|
101
|
+
|
92
102
|
def inspect
|
93
103
|
"#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
|
94
104
|
end
|
data/lib/pry/hooks.rb
CHANGED
@@ -18,11 +18,11 @@ class Pry
|
|
18
18
|
# @param [Hash] hash The hash to convert to `Pry::Hooks`.
|
19
19
|
# @return [Pry::Hooks] The resulting `Pry::Hooks` instance.
|
20
20
|
def self.from_hash(hash)
|
21
|
+
return hash if hash.instance_of?(self)
|
21
22
|
instance = new
|
22
23
|
hash.each do |k, v|
|
23
24
|
instance.add_hook(k, nil, v)
|
24
25
|
end
|
25
|
-
|
26
26
|
instance
|
27
27
|
end
|
28
28
|
|
@@ -49,22 +49,6 @@ class Pry
|
|
49
49
|
@errors ||= []
|
50
50
|
end
|
51
51
|
|
52
|
-
# FIXME:
|
53
|
-
# This is a hack to alert people of the new API.
|
54
|
-
def [](event_name)
|
55
|
-
warn "`Pry.hooks[]` is deprecated! Please use the new `Pry::Hooks` API! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
56
|
-
|
57
|
-
get_hook(event_name, nil)
|
58
|
-
end
|
59
|
-
|
60
|
-
# FIXME:
|
61
|
-
# This is a hack to alert people of the new API.
|
62
|
-
def []=(event_name, callable)
|
63
|
-
warn "`Pry.hooks[]=` is deprecated! Please use the new `Pry::Hooks` API! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
64
|
-
|
65
|
-
add_hook(event_name, nil, callable)
|
66
|
-
end
|
67
|
-
|
68
52
|
# Destructively merge the contents of two `Pry:Hooks` instances.
|
69
53
|
# @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
|
70
54
|
# @return [Pry:Hooks] Returns the receiver.
|
@@ -146,18 +130,14 @@ class Pry
|
|
146
130
|
def exec_hook(event_name, *args, &block)
|
147
131
|
@hooks[event_name] ||= []
|
148
132
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
e
|
158
|
-
end
|
159
|
-
end.last
|
160
|
-
end
|
133
|
+
@hooks[event_name].map do |hook_name, callable|
|
134
|
+
begin
|
135
|
+
callable.call(*args, &block)
|
136
|
+
rescue RescuableException => e
|
137
|
+
errors << e
|
138
|
+
e
|
139
|
+
end
|
140
|
+
end.last
|
161
141
|
end
|
162
142
|
|
163
143
|
# Return the number of hook functions registered for the `event_name` event.
|
@@ -244,9 +224,7 @@ class Pry
|
|
244
224
|
# @param [Symbol] hook_name Name of the hook.
|
245
225
|
# @return [Boolean] Whether the hook by the name `hook_name`
|
246
226
|
def hook_exists?(event_name, hook_name)
|
247
|
-
|
227
|
+
!!(@hooks[event_name] && @hooks[event_name].find { |name, _| name == hook_name })
|
248
228
|
end
|
249
|
-
private :hook_exists?
|
250
|
-
|
251
229
|
end
|
252
230
|
end
|