pry 0.10.0.pre4-x64-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +25 -0
- data/README.md +406 -0
- data/bin/pry +16 -0
- data/lib/pry.rb +161 -0
- data/lib/pry/cli.rb +220 -0
- data/lib/pry/code.rb +341 -0
- 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 +692 -0
- data/lib/pry/command_set.rb +443 -0
- data/lib/pry/commands.rb +6 -0
- 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 +24 -0
- 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 +131 -0
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +5 -0
- data/lib/pry/helpers/base_helpers.rb +113 -0
- data/lib/pry/helpers/command_helpers.rb +156 -0
- data/lib/pry/helpers/documentation_helpers.rb +75 -0
- data/lib/pry/helpers/options_helpers.rb +27 -0
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +107 -0
- data/lib/pry/history.rb +125 -0
- data/lib/pry/history_array.rb +121 -0
- data/lib/pry/hooks.rb +230 -0
- data/lib/pry/indent.rb +406 -0
- 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 +546 -0
- 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 +136 -0
- 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 +103 -0
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +375 -0
- data/lib/pry/pry_instance.rb +654 -0
- data/lib/pry/rbx_path.rb +22 -0
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +74 -0
- 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 +3 -0
- data/lib/pry/wrapped_module.rb +373 -0
- metadata +248 -0
data/lib/pry/rbx_path.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pry
|
2
|
+
module RbxPath
|
3
|
+
module_function
|
4
|
+
def is_core_path?(path)
|
5
|
+
Pry::Helpers::BaseHelpers.rbx? && (path.start_with?("kernel") || path.start_with?("lib")) && File.exist?(convert_path_to_full(path))
|
6
|
+
end
|
7
|
+
|
8
|
+
def convert_path_to_full(path)
|
9
|
+
if path.start_with?("kernel")
|
10
|
+
File.join File.dirname(Rubinius::KERNEL_PATH), path
|
11
|
+
elsif path.start_with?("lib")
|
12
|
+
File.join File.dirname(Rubinius::LIB_PATH), path
|
13
|
+
else
|
14
|
+
path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def rvm_ruby?(path)
|
19
|
+
!!(path =~ /\.rvm/)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/pry/repl.rb
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class REPL
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :@pry, :input, :output
|
7
|
+
|
8
|
+
# @return [Pry] The instance of {Pry} that the user is controlling.
|
9
|
+
attr_accessor :pry
|
10
|
+
|
11
|
+
# Instantiate a new {Pry} instance with the given options, then start a
|
12
|
+
# {REPL} instance wrapping it.
|
13
|
+
# @option options See {Pry#initialize}
|
14
|
+
def self.start(options)
|
15
|
+
new(Pry.new(options)).start
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create an instance of {REPL} wrapping the given {Pry}.
|
19
|
+
# @param [Pry] pry The instance of {Pry} that this {REPL} will control.
|
20
|
+
# @param [Hash] options Options for this {REPL} instance.
|
21
|
+
# @option options [Object] :target The initial target of the session.
|
22
|
+
def initialize(pry, options = {})
|
23
|
+
@pry = pry
|
24
|
+
@indent = Pry::Indent.new
|
25
|
+
|
26
|
+
if options[:target]
|
27
|
+
@pry.push_binding options[:target]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Start the read-eval-print loop.
|
32
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
33
|
+
# thrown with it.
|
34
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
35
|
+
# thrown with it.
|
36
|
+
def start
|
37
|
+
prologue
|
38
|
+
Pry::InputLock.for(:all).with_ownership { repl }
|
39
|
+
ensure
|
40
|
+
epilogue
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Set up the repl session.
|
46
|
+
# @return [void]
|
47
|
+
def prologue
|
48
|
+
pry.exec_hook :before_session, pry.output, pry.current_binding, pry
|
49
|
+
|
50
|
+
# Clear the line before starting Pry. This fixes issue #566.
|
51
|
+
if pry.config.correct_indent
|
52
|
+
Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# The actual read-eval-print loop.
|
57
|
+
#
|
58
|
+
# The {REPL} instance is responsible for reading and looping, whereas the
|
59
|
+
# {Pry} instance is responsible for evaluating user input and printing
|
60
|
+
# return values and command output.
|
61
|
+
#
|
62
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
63
|
+
# thrown with it.
|
64
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
65
|
+
# thrown with it.
|
66
|
+
def repl
|
67
|
+
loop do
|
68
|
+
case val = read
|
69
|
+
when :control_c
|
70
|
+
output.puts ""
|
71
|
+
pry.reset_eval_string
|
72
|
+
when :no_more_input
|
73
|
+
output.puts "" if output.tty?
|
74
|
+
break
|
75
|
+
else
|
76
|
+
output.puts "" if val.nil? && output.tty?
|
77
|
+
return pry.exit_value unless pry.eval(val)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Clean up after the repl session.
|
83
|
+
# @return [void]
|
84
|
+
def epilogue
|
85
|
+
pry.exec_hook :after_session, pry.output, pry.current_binding, pry
|
86
|
+
end
|
87
|
+
|
88
|
+
# Read a line of input from the user.
|
89
|
+
# @return [String] The line entered by the user.
|
90
|
+
# @return [nil] On `<Ctrl-D>`.
|
91
|
+
# @return [:control_c] On `<Ctrl+C>`.
|
92
|
+
# @return [:no_more_input] On EOF.
|
93
|
+
def read
|
94
|
+
@indent.reset if pry.eval_string.empty?
|
95
|
+
current_prompt = pry.select_prompt
|
96
|
+
indentation = pry.config.auto_indent ? @indent.current_prefix : ''
|
97
|
+
|
98
|
+
val = read_line("#{current_prompt}#{indentation}")
|
99
|
+
|
100
|
+
# Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
|
101
|
+
return val unless String === val
|
102
|
+
|
103
|
+
if pry.config.auto_indent
|
104
|
+
original_val = "#{indentation}#{val}"
|
105
|
+
indented_val = @indent.indent(val)
|
106
|
+
|
107
|
+
if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
108
|
+
output.print @indent.correct_indentation(
|
109
|
+
current_prompt, indented_val,
|
110
|
+
original_val.length - indented_val.length
|
111
|
+
)
|
112
|
+
output.flush
|
113
|
+
end
|
114
|
+
else
|
115
|
+
indented_val = val
|
116
|
+
end
|
117
|
+
|
118
|
+
indented_val
|
119
|
+
end
|
120
|
+
|
121
|
+
# Manage switching of input objects on encountering `EOFError`s.
|
122
|
+
# @return [Object] Whatever the given block returns.
|
123
|
+
# @return [:no_more_input] Indicates that no more input can be read.
|
124
|
+
def handle_read_errors
|
125
|
+
should_retry = true
|
126
|
+
exception_count = 0
|
127
|
+
|
128
|
+
begin
|
129
|
+
yield
|
130
|
+
rescue EOFError
|
131
|
+
pry.config.input = Pry.config.input
|
132
|
+
if !should_retry
|
133
|
+
output.puts "Error: Pry ran out of things to read from! " \
|
134
|
+
"Attempting to break out of REPL."
|
135
|
+
return :no_more_input
|
136
|
+
end
|
137
|
+
should_retry = false
|
138
|
+
retry
|
139
|
+
|
140
|
+
# Handle <Ctrl+C> like Bash: empty the current input buffer, but don't
|
141
|
+
# quit. This is only for MRI 1.9; other versions of Ruby don't let you
|
142
|
+
# send Interrupt from within Readline.
|
143
|
+
rescue Interrupt
|
144
|
+
return :control_c
|
145
|
+
|
146
|
+
# If we get a random error when trying to read a line we don't want to
|
147
|
+
# automatically retry, as the user will see a lot of error messages
|
148
|
+
# scroll past and be unable to do anything about it.
|
149
|
+
rescue RescuableException => e
|
150
|
+
puts "Error: #{e.message}"
|
151
|
+
output.puts e.backtrace
|
152
|
+
exception_count += 1
|
153
|
+
if exception_count < 5
|
154
|
+
retry
|
155
|
+
end
|
156
|
+
puts "FATAL: Pry failed to get user input using `#{input}`."
|
157
|
+
puts "To fix this you may be able to pass input and output file " \
|
158
|
+
"descriptors to pry directly. e.g."
|
159
|
+
puts " Pry.config.input = STDIN"
|
160
|
+
puts " Pry.config.output = STDOUT"
|
161
|
+
puts " binding.pry"
|
162
|
+
return :no_more_input
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns the next line of input to be sent to the {Pry} instance.
|
167
|
+
# @param [String] current_prompt The prompt to use for input.
|
168
|
+
# @return [String?] The next line of input, or `nil` on <Ctrl-D>.
|
169
|
+
def read_line(current_prompt)
|
170
|
+
handle_read_errors do
|
171
|
+
if defined? Coolline and input.is_a? Coolline
|
172
|
+
input.completion_proc = proc do |cool|
|
173
|
+
completions = @pry.complete cool.completed_word
|
174
|
+
completions.compact
|
175
|
+
end
|
176
|
+
elsif input.respond_to? :completion_proc=
|
177
|
+
input.completion_proc = proc do |input|
|
178
|
+
@pry.complete input
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
if defined?(Readline) and input == Readline
|
183
|
+
input_readline(current_prompt, false) # false since we'll add it manually
|
184
|
+
elsif defined? Coolline and input.is_a? Coolline
|
185
|
+
input_readline(current_prompt)
|
186
|
+
else
|
187
|
+
if input.method(:readline).arity == 1
|
188
|
+
input_readline(current_prompt)
|
189
|
+
else
|
190
|
+
input_readline
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def input_readline(*args)
|
197
|
+
Pry::InputLock.for(:all).interruptible_region do
|
198
|
+
input.readline(*args)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class Pry
|
2
|
+
|
3
|
+
# A class to manage the loading of files through the REPL loop.
|
4
|
+
# This is an interesting trick as it processes your file as if it
|
5
|
+
# was user input in an interactive session. As a result, all Pry
|
6
|
+
# commands are available, and they are executed non-interactively. Furthermore
|
7
|
+
# the session becomes interactive when the repl loop processes a
|
8
|
+
# 'make-interactive' command in the file. The session also becomes
|
9
|
+
# interactive when an exception is encountered, enabling you to fix
|
10
|
+
# the error before returning to non-interactive processing with the
|
11
|
+
# 'make-non-interactive' command.
|
12
|
+
|
13
|
+
class REPLFileLoader
|
14
|
+
def initialize(file_name)
|
15
|
+
full_name = File.expand_path(file_name)
|
16
|
+
raise RuntimeError, "No such file: #{full_name}" if !File.exists?(full_name)
|
17
|
+
|
18
|
+
define_additional_commands
|
19
|
+
@content = File.read(full_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Switch to interactive mode, i.e take input from the user
|
23
|
+
# and use the regular print and exception handlers.
|
24
|
+
# @param [Pry] _pry_ the Pry instance to make interactive.
|
25
|
+
def interactive_mode(_pry_)
|
26
|
+
_pry_.config.input = Pry.config.input
|
27
|
+
_pry_.config.print = Pry.config.print
|
28
|
+
_pry_.config.exception_handler = Pry.config.exception_handler
|
29
|
+
Pry::REPL.new(_pry_).start
|
30
|
+
end
|
31
|
+
|
32
|
+
# Switch to non-interactive mode. Essentially
|
33
|
+
# this means there is no result output
|
34
|
+
# and that the session becomes interactive when an exception is encountered.
|
35
|
+
# @param [Pry] _pry_ the Pry instance to make non-interactive.
|
36
|
+
def non_interactive_mode(_pry_, content)
|
37
|
+
_pry_.print = proc {}
|
38
|
+
_pry_.exception_handler = proc do |o, e, _p_|
|
39
|
+
_p_.run_command "cat --ex"
|
40
|
+
o.puts "...exception encountered, going interactive!"
|
41
|
+
interactive_mode(_pry_)
|
42
|
+
end
|
43
|
+
|
44
|
+
content.lines.each do |line|
|
45
|
+
break unless _pry_.eval line, :generated => true
|
46
|
+
end
|
47
|
+
|
48
|
+
unless _pry_.eval_string.empty?
|
49
|
+
_pry_.output.puts "#{_pry_.eval_string}...exception encountered, going interactive!"
|
50
|
+
interactive_mode(_pry_)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Define a few extra commands useful for flipping back & forth
|
55
|
+
# between interactive/non-interactive modes
|
56
|
+
def define_additional_commands
|
57
|
+
s = self
|
58
|
+
|
59
|
+
Pry::Commands.command "make-interactive", "Make the session interactive" do
|
60
|
+
s.interactive_mode(_pry_)
|
61
|
+
end
|
62
|
+
|
63
|
+
Pry::Commands.command "load-file", "Load another file through the repl" do |file_name|
|
64
|
+
s.non_interactive_mode(_pry_, File.read(File.expand_path(file_name)))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Actually load the file through the REPL by setting file content
|
69
|
+
# as the REPL input stream.
|
70
|
+
def load
|
71
|
+
non_interactive_mode(Pry.new, @content)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/pry/rubygem.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
module Rubygem
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def installed?(name)
|
8
|
+
if Gem::Specification.respond_to?(:find_all_by_name)
|
9
|
+
Gem::Specification.find_all_by_name(name).any?
|
10
|
+
else
|
11
|
+
Gem.source_index.find_name(name).first
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get the gem spec object for the given gem name.
|
16
|
+
#
|
17
|
+
# @param [String] name
|
18
|
+
# @return [Gem::Specification]
|
19
|
+
def spec(name)
|
20
|
+
specs = if Gem::Specification.respond_to?(:each)
|
21
|
+
Gem::Specification.find_all_by_name(name)
|
22
|
+
else
|
23
|
+
Gem.source_index.find_name(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
|
27
|
+
|
28
|
+
first_spec or raise CommandError, "Gem `#{name}` not found"
|
29
|
+
end
|
30
|
+
|
31
|
+
# List gems matching a pattern.
|
32
|
+
#
|
33
|
+
# @param [Regexp] pattern
|
34
|
+
# @return [Array<Gem::Specification>]
|
35
|
+
def list(pattern = /.*/)
|
36
|
+
if Gem::Specification.respond_to?(:each)
|
37
|
+
Gem::Specification.select{|spec| spec.name =~ pattern }
|
38
|
+
else
|
39
|
+
Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Completion function for gem-cd and gem-open.
|
44
|
+
#
|
45
|
+
# @param [String] so_far what the user's typed so far
|
46
|
+
# @return [Array<String>] completions
|
47
|
+
def complete(so_far)
|
48
|
+
if so_far =~ / ([^ ]*)\z/
|
49
|
+
self.list(%r{\A#{$2}}).map(&:name)
|
50
|
+
else
|
51
|
+
self.list.map(&:name)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Installs a gem with all its dependencies.
|
56
|
+
#
|
57
|
+
# @param [String] name
|
58
|
+
# @return [void]
|
59
|
+
def install(name)
|
60
|
+
gemrc_opts = Gem.configuration['gem'].split(' ')
|
61
|
+
destination = if gemrc_opts.include?('--user-install')
|
62
|
+
Gem.user_dir
|
63
|
+
elsif File.writable?(Gem.dir)
|
64
|
+
Gem.dir
|
65
|
+
else
|
66
|
+
Gem.user_dir
|
67
|
+
end
|
68
|
+
installer = Gem::DependencyInstaller.new(:install_dir => destination)
|
69
|
+
installer.install(name)
|
70
|
+
rescue Errno::EACCES
|
71
|
+
raise CommandError,
|
72
|
+
"Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
|
73
|
+
rescue Gem::GemNotFoundException
|
74
|
+
raise CommandError,
|
75
|
+
"Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
|
76
|
+
else
|
77
|
+
Gem.refresh
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/pry/terminal.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
class Pry::Terminal
|
2
|
+
class << self
|
3
|
+
# Return a pair of [rows, columns] which gives the size of the window.
|
4
|
+
#
|
5
|
+
# If the window size cannot be determined, return nil.
|
6
|
+
def screen_size
|
7
|
+
rows, cols = actual_screen_size
|
8
|
+
if rows && cols
|
9
|
+
[rows.to_i, cols.to_i]
|
10
|
+
else
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return a screen size or a default if that fails.
|
16
|
+
def size! default = [27, 80]
|
17
|
+
screen_size || default
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return a screen width or the default if that fails.
|
21
|
+
def width!
|
22
|
+
size![1]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return a screen height or the default if that fails.
|
26
|
+
def height!
|
27
|
+
size![0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def actual_screen_size
|
31
|
+
# The best way, if possible (requires non-jruby ≥1.9 or io-console gem)
|
32
|
+
screen_size_according_to_io_console or
|
33
|
+
# Fall back to the old standby, though it might be stale:
|
34
|
+
screen_size_according_to_env or
|
35
|
+
# Fall further back, though this one is also out of date without something
|
36
|
+
# calling Readline.set_screen_size
|
37
|
+
screen_size_according_to_readline or
|
38
|
+
# Windows users can otherwise run ansicon and get a decent answer:
|
39
|
+
screen_size_according_to_ansicon_env
|
40
|
+
end
|
41
|
+
|
42
|
+
def screen_size_according_to_io_console
|
43
|
+
return if Pry::Helpers::BaseHelpers.jruby?
|
44
|
+
require 'io/console'
|
45
|
+
$stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
|
46
|
+
rescue LoadError
|
47
|
+
# They probably don't have the io/console stdlib or the io-console gem.
|
48
|
+
# We'll keep trying.
|
49
|
+
end
|
50
|
+
|
51
|
+
def screen_size_according_to_env
|
52
|
+
size = [ENV['LINES'] || ENV['ROWS'], ENV['COLUMNS']]
|
53
|
+
size if nonzero_column?(size)
|
54
|
+
end
|
55
|
+
|
56
|
+
def screen_size_according_to_readline
|
57
|
+
if defined?(Readline) && Readline.respond_to?(:get_screen_size)
|
58
|
+
size = Readline.get_screen_size
|
59
|
+
size if nonzero_column?(size)
|
60
|
+
end
|
61
|
+
rescue Java::JavaLang::NullPointerException
|
62
|
+
# This rescue won't happen on jrubies later than:
|
63
|
+
# https://github.com/jruby/jruby/pull/436
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def screen_size_according_to_ansicon_env
|
68
|
+
return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
|
69
|
+
size = [$2, $1]
|
70
|
+
size if nonzero_column?(size)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def nonzero_column?(size)
|
76
|
+
size[1].to_i > 0
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|