pry 0.12.0-java → 0.14.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +162 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry.rb +132 -119
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +43 -51
- data/lib/pry/code.rb +40 -28
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit.rb +184 -161
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/exit.rb +39 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +80 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -45
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression.rb +89 -86
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config.rb +307 -25
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +20 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +17 -14
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method.rb +141 -94
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +186 -180
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -103
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- metadata +37 -37
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/plugins.rb +0 -122
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
data/lib/pry/commands/bang.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class Command
|
5
|
+
class Bang < Pry::ClassCommand
|
6
|
+
match(/^\s*!\s*$/)
|
7
|
+
group 'Editing'
|
8
|
+
description 'Clear the input buffer.'
|
9
|
+
command_options use_prefix: false, listing: '!'
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
banner <<-'BANNER'
|
12
|
+
Clear the input buffer. Useful if the parsing process goes wrong and you get
|
13
|
+
stuck in the read loop.
|
14
|
+
BANNER
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
def process
|
17
|
+
output.puts 'Input buffer cleared!'
|
18
|
+
eval_string.replace('')
|
19
|
+
end
|
16
20
|
end
|
17
|
-
end
|
18
21
|
|
19
|
-
|
22
|
+
Pry::Commands.add_command(Pry::Command::Bang)
|
23
|
+
end
|
20
24
|
end
|
@@ -1,17 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class BangPry < Pry::ClassCommand
|
6
|
+
match '!pry'
|
7
|
+
group 'Navigating Pry'
|
8
|
+
description 'Start a Pry session on current self.'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Start a Pry session on current self. Also works mid multi-line expression.
|
12
|
+
BANNER
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
def process
|
15
|
+
target.pry
|
16
|
+
end
|
13
17
|
end
|
14
|
-
end
|
15
18
|
|
16
|
-
|
19
|
+
Pry::Commands.add_command(Pry::Command::BangPry)
|
20
|
+
end
|
17
21
|
end
|
data/lib/pry/commands/cat.rb
CHANGED
@@ -1,63 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
match 'cat'
|
9
|
-
group 'Input and Output'
|
10
|
-
description "Show code from a file, Pry's input buffer, or the last exception."
|
11
|
-
|
12
|
-
banner <<-'BANNER'
|
13
|
-
Usage: cat FILE
|
14
|
-
cat --ex [STACK_INDEX]
|
15
|
-
cat --in [INPUT_INDEX_OR_RANGE]
|
16
|
-
|
17
|
-
`cat` is capable of showing part or all of a source file, the context of the
|
18
|
-
last exception, or an expression from Pry's input history.
|
19
|
-
|
20
|
-
`cat --ex` defaults to showing the lines surrounding the location of the last
|
21
|
-
exception. Invoking it more than once travels up the exception's backtrace, and
|
22
|
-
providing a number shows the context of the given index of the backtrace.
|
23
|
-
BANNER
|
24
|
-
|
25
|
-
def options(opt)
|
26
|
-
opt.on :ex, "Show the context of the last exception", optional_argument: true, as: Integer
|
27
|
-
opt.on :i, :in, "Show one or more entries from Pry's expression history", optional_argument: true, as: Range, default: -5..-1
|
28
|
-
opt.on :s, :start, "Starting line (defaults to the first line)", optional_argument: true, as: Integer
|
29
|
-
opt.on :e, :end, "Ending line (defaults to the last line)", optional_argument: true, as: Integer
|
30
|
-
opt.on :l, :'line-numbers', "Show line numbers"
|
31
|
-
opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", argument: true, as: Symbol
|
32
|
-
end
|
4
|
+
class Command
|
5
|
+
class Cat < Pry::ClassCommand
|
6
|
+
match 'cat'
|
7
|
+
group 'Input and Output'
|
8
|
+
description "Show code from a file, Pry's input buffer, or the last exception."
|
33
9
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
when opts.present?(:in)
|
39
|
-
InputExpressionFormatter.new(_pry_.input_ring, opts).format
|
40
|
-
else
|
41
|
-
FileFormatter.new(args.first, _pry_, opts).format
|
42
|
-
end
|
43
|
-
|
44
|
-
_pry_.pager.page output
|
45
|
-
end
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: cat FILE
|
12
|
+
cat --ex [STACK_INDEX]
|
13
|
+
cat --in [INPUT_INDEX_OR_RANGE]
|
46
14
|
|
47
|
-
|
48
|
-
|
49
|
-
|
15
|
+
`cat` is capable of showing part or all of a source file, the context of the
|
16
|
+
last exception, or an expression from Pry's input history.
|
17
|
+
|
18
|
+
`cat --ex` defaults to showing the lines surrounding the location of the last
|
19
|
+
exception. Invoking it more than once travels up the exception's backtrace, and
|
20
|
+
providing a number shows the context of the given index of the backtrace.
|
21
|
+
BANNER
|
22
|
+
|
23
|
+
def options(opt)
|
24
|
+
opt.on :ex, "Show the context of the last exception",
|
25
|
+
optional_argument: true, as: Integer
|
26
|
+
opt.on :i, :in, "Show one or more entries from Pry's expression history",
|
27
|
+
optional_argument: true, as: Range, default: -5..-1
|
28
|
+
opt.on :s, :start, "Starting line (defaults to the first line)",
|
29
|
+
optional_argument: true, as: Integer
|
30
|
+
opt.on :e, :end, "Ending line (defaults to the last line)",
|
31
|
+
optional_argument: true, as: Integer
|
32
|
+
opt.on :l, :'line-numbers', "Show line numbers"
|
33
|
+
opt.on :t, :type, "The file type for syntax highlighting " \
|
34
|
+
"(e.g., 'ruby' or 'python')",
|
35
|
+
argument: true, as: Symbol
|
36
|
+
end
|
50
37
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
def process
|
39
|
+
output =
|
40
|
+
if opts.present?(:ex)
|
41
|
+
ExceptionFormatter.new(
|
42
|
+
pry_instance.last_exception, pry_instance, opts
|
43
|
+
).format
|
44
|
+
elsif opts.present?(:in)
|
45
|
+
InputExpressionFormatter.new(pry_instance.input_ring, opts).format
|
46
|
+
else
|
47
|
+
FileFormatter.new(args.first, pry_instance, opts).format
|
48
|
+
end
|
55
49
|
|
56
|
-
|
57
|
-
|
50
|
+
pry_instance.pager.page output
|
51
|
+
end
|
52
|
+
|
53
|
+
def complete(search)
|
54
|
+
super | load_path_completions
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_path_completions
|
58
|
+
$LOAD_PATH.flat_map do |path|
|
59
|
+
Dir[path + '/**/*'].map do |f|
|
60
|
+
next if File.directory?(f)
|
61
|
+
|
62
|
+
f.sub!(path + '/', '')
|
63
|
+
end
|
64
|
+
end
|
58
65
|
end
|
59
66
|
end
|
60
|
-
end
|
61
67
|
|
62
|
-
|
68
|
+
Pry::Commands.add_command(Pry::Command::Cat)
|
69
|
+
end
|
63
70
|
end
|
@@ -1,26 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
class
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class Cat
|
6
|
+
class AbstractFormatter
|
7
|
+
include Pry::Helpers::CommandHelpers
|
8
|
+
include Pry::Helpers::BaseHelpers
|
6
9
|
|
7
|
-
|
8
|
-
def decorate(content)
|
9
|
-
content.code_type = code_type
|
10
|
-
content.between(*between_lines).
|
11
|
-
with_line_numbers(use_line_numbers?).highlighted
|
12
|
-
end
|
10
|
+
private
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def decorate(content)
|
13
|
+
content.code_type = code_type
|
14
|
+
content.between(*between_lines)
|
15
|
+
.with_line_numbers(use_line_numbers?).highlighted
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def code_type
|
19
|
+
opts[:type] || :ruby
|
20
|
+
end
|
21
|
+
|
22
|
+
def use_line_numbers?
|
23
|
+
opts.present?(:'line-numbers') || opts.present?(:ex)
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
def between_lines
|
27
|
+
[opts[:start] || 1, opts[:end] || -1]
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
@@ -1,78 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Command
|
5
|
+
class Cat
|
6
|
+
class ExceptionFormatter < AbstractFormatter
|
7
|
+
attr_reader :ex
|
8
|
+
attr_reader :opts
|
9
|
+
attr_reader :pry_instance
|
10
|
+
include Pry::Helpers::Text
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def initialize(exception, pry_instance, opts)
|
13
|
+
@ex = exception
|
14
|
+
@opts = opts
|
15
|
+
@pry_instance = pry_instance
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def format
|
19
|
+
check_for_errors
|
20
|
+
set_file_and_dir_locals(
|
21
|
+
backtrace_file, pry_instance, pry_instance.current_context
|
22
|
+
)
|
23
|
+
code = decorate(
|
24
|
+
Pry::Code.from_file(backtrace_file)
|
25
|
+
.between(*start_and_end_line_for_code_window)
|
26
|
+
.with_marker(backtrace_line)
|
27
|
+
)
|
28
|
+
"#{header}#{code}"
|
29
|
+
end
|
23
30
|
|
24
|
-
|
31
|
+
private
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
def code_window_size
|
34
|
+
pry_instance.config.default_window_size || 5
|
35
|
+
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def backtrace_level
|
38
|
+
@backtrace_level ||=
|
39
|
+
begin
|
40
|
+
bl =
|
41
|
+
if opts[:ex].nil?
|
42
|
+
ex.bt_index
|
43
|
+
else
|
44
|
+
ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
|
45
|
+
end
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
increment_backtrace_level
|
48
|
+
bl
|
49
|
+
end
|
50
|
+
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
52
|
+
def increment_backtrace_level
|
53
|
+
ex.inc_bt_index
|
54
|
+
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
def backtrace_file
|
57
|
+
Array(ex.bt_source_location_for(backtrace_level)).first
|
58
|
+
end
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
def backtrace_line
|
61
|
+
Array(ex.bt_source_location_for(backtrace_level)).last
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
64
|
+
def check_for_errors
|
65
|
+
raise CommandError, "No exception found." unless ex
|
66
|
+
return if backtrace_file
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
start_line = 1 if start_line < 1
|
68
|
+
raise CommandError, "The given backtrace level is out of bounds."
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
71
|
+
def start_and_end_line_for_code_window
|
72
|
+
start_line = backtrace_line - code_window_size
|
73
|
+
start_line = 1 if start_line < 1
|
68
74
|
|
69
|
-
|
70
|
-
|
71
|
-
#{bold 'Exception:'} #{ex.class}: #{ex.message}
|
72
|
-
--
|
73
|
-
#{bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
|
75
|
+
[start_line, backtrace_line + code_window_size]
|
76
|
+
end
|
74
77
|
|
75
|
-
|
78
|
+
def header
|
79
|
+
unindent(
|
80
|
+
"#{bold 'Exception:'} #{ex.class}: #{ex.message}\n" \
|
81
|
+
"--\n" \
|
82
|
+
"#{bold('From:')} #{backtrace_file}:#{backtrace_line} @ " \
|
83
|
+
"#{bold("level: #{backtrace_level}")} of backtrace " \
|
84
|
+
"(of #{ex.backtrace.size - 1}).\n\n"
|
85
|
+
)
|
86
|
+
end
|
76
87
|
end
|
77
88
|
end
|
78
89
|
end
|
@@ -1,69 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class Command
|
5
|
+
class Cat
|
6
|
+
class FileFormatter < AbstractFormatter
|
7
|
+
attr_reader :file_with_embedded_line
|
8
|
+
attr_reader :opts
|
9
|
+
attr_reader :pry_instance
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
def initialize(file_with_embedded_line, pry_instance, opts)
|
12
|
+
unless file_with_embedded_line
|
13
|
+
raise CommandError, "Must provide a filename, --in, or --ex."
|
14
|
+
end
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
@file_with_embedded_line = file_with_embedded_line
|
17
|
+
@opts = opts
|
18
|
+
@pry_instance = pry_instance
|
19
|
+
@code_from_file = Pry::Code.from_file(file_name)
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
def format
|
23
|
+
set_file_and_dir_locals(file_name, pry_instance, pry_instance.current_context)
|
24
|
+
decorate(@code_from_file)
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
def file_and_line
|
28
|
+
file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})
|
24
29
|
|
25
|
-
|
26
|
-
|
30
|
+
[file_name, line_num ? line_num.to_i : nil]
|
31
|
+
end
|
27
32
|
|
28
|
-
|
33
|
+
private
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
def file_name
|
36
|
+
file_and_line.first
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
def line_number
|
40
|
+
file_and_line.last
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
def code_window_size
|
44
|
+
pry_instance.config.default_window_size || 7
|
45
|
+
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
def decorate(content)
|
48
|
+
if line_number
|
49
|
+
super(content.around(line_number, code_window_size))
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
47
53
|
end
|
48
|
-
end
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
|
55
|
+
def code_type
|
56
|
+
opts[:type] || detect_code_type_from_file(file_name)
|
57
|
+
end
|
53
58
|
|
54
|
-
|
55
|
-
|
59
|
+
def detect_code_type_from_file(file_name)
|
60
|
+
code_type = @code_from_file.code_type
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
if code_type == :unknown
|
63
|
+
name = File.basename(file_name).split('.', 2).first
|
64
|
+
case name
|
65
|
+
when "Rakefile", "Gemfile"
|
66
|
+
:ruby
|
67
|
+
else
|
68
|
+
:text
|
69
|
+
end
|
62
70
|
else
|
63
|
-
|
71
|
+
code_type
|
64
72
|
end
|
65
|
-
else
|
66
|
-
code_type
|
67
73
|
end
|
68
74
|
end
|
69
75
|
end
|