2017-11-02 01:02:41 +01:00
|
|
|
module Pry::Helpers; end
|
2018-11-03 18:20:20 +08:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
module Pry::Helpers::BaseHelpers
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def silence_warnings
|
|
|
|
old_verbose = $VERBOSE
|
|
|
|
$VERBOSE = nil
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$VERBOSE = old_verbose
|
|
|
|
end
|
|
|
|
end
|
2017-10-22 17:07:47 +02:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
# Acts like send but ignores any methods defined below Object or Class in the
|
|
|
|
# inheritance hierarchy.
|
|
|
|
# This is required to introspect methods on objects like Net::HTTP::Get that
|
|
|
|
# have overridden the `method` method.
|
|
|
|
def safe_send(obj, method, *args, &block)
|
|
|
|
(Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
|
|
|
|
end
|
|
|
|
public :safe_send
|
2011-12-26 18:48:59 -06:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
def find_command(name, set = Pry::Commands)
|
|
|
|
command_match = set.find do |_, command|
|
|
|
|
(listing = command.options[:listing]) == name && listing != nil
|
|
|
|
end
|
|
|
|
command_match.last if command_match
|
|
|
|
end
|
2012-06-23 15:06:32 -07:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
def not_a_real_file?(file)
|
|
|
|
file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
|
|
|
|
end
|
2011-09-01 15:47:29 +12:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
def command_dependencies_met?(options)
|
|
|
|
return true if !options[:requires_gem]
|
2018-10-14 09:44:58 -04:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
Array(options[:requires_gem]).all? do |g|
|
|
|
|
Pry::Rubygem.installed?(g)
|
|
|
|
end
|
|
|
|
end
|
2013-02-04 17:57:00 +02:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
def use_ansi_codes?
|
2018-11-02 00:16:35 +08:00
|
|
|
Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
2017-11-02 01:02:41 +01:00
|
|
|
end
|
2011-08-23 13:41:27 +12:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
def colorize_code(code)
|
|
|
|
CodeRay.scan(code, :ruby).term
|
|
|
|
end
|
2013-09-06 06:22:34 -07:00
|
|
|
|
2018-11-04 17:34:24 +08:00
|
|
|
def highlight(string, regexp, highlight_color = :bright_yellow)
|
2017-11-02 01:02:41 +01:00
|
|
|
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
|
|
|
end
|
2014-04-28 23:12:56 -07:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
# formatting
|
|
|
|
def heading(text)
|
|
|
|
text = "#{text}\n--"
|
|
|
|
"\e[1m#{text}\e[0m"
|
|
|
|
end
|
2012-04-13 14:55:30 +12:00
|
|
|
|
2017-11-02 01:02:41 +01:00
|
|
|
# Send the given text through the best available pager (if Pry.config.pager is
|
|
|
|
# enabled). Infers where to send the output if used as a mixin.
|
|
|
|
# DEPRECATED.
|
2018-10-14 14:56:53 +08:00
|
|
|
def stagger_output(text, _out = nil)
|
2017-11-02 01:02:41 +01:00
|
|
|
if defined?(_pry_) && _pry_
|
|
|
|
_pry_.pager.page text
|
|
|
|
else
|
|
|
|
Pry.new.pager.page text
|
2011-04-13 12:48:50 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|