mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Deprecate Pry::Command#text. Please use black(), white(), etc directly (#1701)
instead (as you would with helper functions from BaseHelpers and CommandHelpers)
This commit is contained in:
parent
4ac9eb3dfb
commit
7c1a652c6b
18 changed files with 52 additions and 36 deletions
|
@ -2,6 +2,12 @@
|
|||
|
||||
#### Features
|
||||
|
||||
* Deprecate Pry::Command#text. Please use black(), white(), etc directly
|
||||
instead (as you would with helper functions from BaseHelpers and
|
||||
CommandHelpers)
|
||||
|
||||
See pull request [#1701](https://github.com/pry/pry/pull/1701).
|
||||
|
||||
* Add Pry::Testable, an improved modular replacement for PryTestHelpers.
|
||||
**breaking change**.
|
||||
|
||||
|
|
|
@ -254,6 +254,14 @@ class Pry
|
|||
command_set.to_hash
|
||||
end
|
||||
|
||||
#
|
||||
# @deprecated
|
||||
# Please use black(), white(), etc directly instead (as you would with helper
|
||||
# functions from BaseHelpers and CommandHelpers)
|
||||
#
|
||||
# @return [Module]
|
||||
# Returns Pry::Helpers::Text
|
||||
#
|
||||
def text
|
||||
Pry::Helpers::Text
|
||||
end
|
||||
|
@ -264,6 +272,7 @@ class Pry
|
|||
|
||||
include Pry::Helpers::BaseHelpers
|
||||
include Pry::Helpers::CommandHelpers
|
||||
include Pry::Helpers::Text
|
||||
|
||||
# Instantiate a command, in preparation for calling it.
|
||||
# @param [Hash] context The runtime context to use with this command.
|
||||
|
|
|
@ -4,6 +4,7 @@ class Pry
|
|||
attr_reader :ex
|
||||
attr_reader :opts
|
||||
attr_reader :_pry_
|
||||
include Pry::Helpers::Text
|
||||
|
||||
def initialize(exception, _pry_, opts)
|
||||
@ex = exception
|
||||
|
@ -66,9 +67,9 @@ class Pry
|
|||
|
||||
def header
|
||||
unindent %{
|
||||
#{Helpers::Text.bold 'Exception:'} #{ex.class}: #{ex.message}
|
||||
#{bold 'Exception:'} #{ex.class}: #{ex.message}
|
||||
--
|
||||
#{Helpers::Text.bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{Helpers::Text.bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
|
||||
#{bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
|
||||
|
||||
}
|
||||
end
|
||||
|
|
|
@ -86,7 +86,7 @@ TEXT
|
|||
prev_color = _pry_.config.color
|
||||
_pry_.config.color = true
|
||||
|
||||
picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
|
||||
picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| red(s) }
|
||||
____ _______________________
|
||||
/ \ | A W G |
|
||||
/ O O \ | N I O N ! |
|
||||
|
|
|
@ -54,7 +54,7 @@ class Pry
|
|||
# @param [Array] matches
|
||||
def show_search_results(matches)
|
||||
if matches.empty?
|
||||
output.puts text.bold("No Methods Matched")
|
||||
output.puts bold("No Methods Matched")
|
||||
else
|
||||
print_matches(matches)
|
||||
end
|
||||
|
@ -88,7 +88,7 @@ class Pry
|
|||
|
||||
# Print matched methods for a class
|
||||
def print_matches_for_class(klass, grouped)
|
||||
output.puts text.bold(klass.name)
|
||||
output.puts bold(klass.name)
|
||||
grouped[klass].each do |method|
|
||||
header = method.name_with_owner
|
||||
output.puts header + additional_info(header, method)
|
||||
|
|
|
@ -20,7 +20,7 @@ class Pry
|
|||
|
||||
def process(gem)
|
||||
Rubygem.install(gem)
|
||||
output.puts "Gem `#{ text.green(gem) }` installed."
|
||||
output.puts "Gem `#{ green(gem) }` installed."
|
||||
require gem
|
||||
rescue LoadError
|
||||
require_path = gem.split('-').join('/')
|
||||
|
|
|
@ -21,10 +21,10 @@ class Pry
|
|||
end
|
||||
|
||||
versions = specs.each_with_index.map do |spec, index|
|
||||
index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
|
||||
index == 0 ? bright_green(spec.version.to_s) : green(spec.version.to_s)
|
||||
end
|
||||
|
||||
output.puts "#{text.default gem} (#{versions.join ', '})"
|
||||
output.puts "#{default gem} (#{versions.join ', '})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ private
|
|||
def list_as_string(gems, limit = 10)
|
||||
gems[0..limit-1].map do |gem|
|
||||
name, version, info = gem.values_at 'name', 'version', 'info'
|
||||
"#{text.bold(name)} #{text.bold('v'+version)} \n#{info}\n\n"
|
||||
"#{bold(name)} #{bold('v'+version)} \n#{info}\n\n"
|
||||
end.join
|
||||
end
|
||||
Pry::Commands.add_command(self)
|
||||
|
|
|
@ -59,7 +59,7 @@ class Pry
|
|||
# @param [Array<Pry::Command>] commands
|
||||
# @return [String] The generated help string.
|
||||
def help_text_for_commands(name, commands)
|
||||
"#{text.bold(name.capitalize)}\n" << commands.map do |command|
|
||||
"#{bold(name.capitalize)}\n" << commands.map do |command|
|
||||
" #{command.options[:listing].to_s.ljust(18)} #{command.description.capitalize}"
|
||||
end.join("\n")
|
||||
end
|
||||
|
|
|
@ -16,21 +16,21 @@ class Pry
|
|||
command = find_command(name)
|
||||
|
||||
unless command
|
||||
output.puts "Command #{ text.green(name) } is not found"
|
||||
output.puts "Command #{ green(name) } is not found"
|
||||
return
|
||||
end
|
||||
|
||||
if command_dependencies_met?(command.options)
|
||||
output.puts "Dependencies for #{ text.green(name) } are met. Nothing to do"
|
||||
output.puts "Dependencies for #{ green(name) } are met. Nothing to do"
|
||||
return
|
||||
end
|
||||
|
||||
output.puts "Attempting to install #{ text.green(name) } command..."
|
||||
output.puts "Attempting to install #{ green(name) } command..."
|
||||
gems_to_install = Array(command.options[:requires_gem])
|
||||
|
||||
gems_to_install.each do |g|
|
||||
next if Rubygem.installed?(g)
|
||||
output.puts "Installing #{ text.green(g) } gem..."
|
||||
output.puts "Installing #{ green(g) } gem..."
|
||||
Rubygem.install(g)
|
||||
end
|
||||
|
||||
|
@ -38,14 +38,14 @@ class Pry
|
|||
begin
|
||||
require g
|
||||
rescue LoadError
|
||||
fail_msg = "Required gem #{ text.green(g) } installed but not found."
|
||||
fail_msg = "Required gem #{ green(g) } installed but not found."
|
||||
fail_msg += " Aborting command installation\n"
|
||||
fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
|
||||
raise CommandError, fail_msg
|
||||
end
|
||||
end
|
||||
|
||||
output.puts "Installation of #{ text.green(name) } successful! Type `help #{name}` for information"
|
||||
output.puts "Installation of #{ green(name) } successful! Type `help #{name}` for information"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Pry::Command::ListInspectors < Pry::ClassCommand
|
|||
def process
|
||||
output.puts heading("Available inspectors") + "\n"
|
||||
inspector_map.each do |name, inspector|
|
||||
output.write "Name: #{text.bold(name)}"
|
||||
output.write "Name: #{bold(name)}"
|
||||
output.puts selected_inspector?(inspector) ? selected_text : ""
|
||||
output.puts inspector[:description]
|
||||
output.puts
|
||||
|
@ -25,7 +25,7 @@ private
|
|||
end
|
||||
|
||||
def selected_text
|
||||
text.red " (selected) "
|
||||
red " (selected) "
|
||||
end
|
||||
|
||||
def selected_inspector?(inspector)
|
||||
|
|
|
@ -12,7 +12,7 @@ class Pry::Command::ListPrompts < Pry::ClassCommand
|
|||
def process
|
||||
output.puts heading("Available prompts") + "\n"
|
||||
prompt_map.each do |name, prompt|
|
||||
output.write "Name: #{text.bold(name)}"
|
||||
output.write "Name: #{bold(name)}"
|
||||
output.puts selected_prompt?(prompt) ? selected_text : ""
|
||||
output.puts prompt[:description]
|
||||
output.puts
|
||||
|
@ -25,7 +25,7 @@ private
|
|||
end
|
||||
|
||||
def selected_text
|
||||
text.red " (selected) "
|
||||
red " (selected) "
|
||||
end
|
||||
|
||||
def selected_prompt?(prompt)
|
||||
|
|
|
@ -17,7 +17,7 @@ class Pry
|
|||
BANNER
|
||||
|
||||
def process
|
||||
_pry_.pager.page text.bold('Backtrace:') << "\n--\n" << _pry_.backtrace.join("\n")
|
||||
_pry_.pager.page bold('Backtrace:') << "\n--\n" << _pry_.backtrace.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -100,11 +100,11 @@ class Pry
|
|||
# object types: methods, modules, commands, procs...
|
||||
def header(code_object)
|
||||
file_name, line_num = file_and_line_for(code_object)
|
||||
h = "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} "
|
||||
h = "\n#{bold('From:')} #{file_name} "
|
||||
h << code_object_header(code_object, line_num)
|
||||
h << "\n#{Pry::Helpers::Text.bold('Number of lines:')} " <<
|
||||
h << "\n#{bold('Number of lines:')} " <<
|
||||
"#{content_for(code_object).lines.count}\n\n"
|
||||
h << Helpers::Text.bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
|
||||
h << bold('** Warning:') << " Cannot find code for #{@original_code_object.nonblank_name}. Showing superclass #{code_object.nonblank_name} instead. **\n\n" if @used_super
|
||||
h
|
||||
end
|
||||
|
||||
|
@ -133,11 +133,11 @@ class Pry
|
|||
def module_header(code_object, line_num)
|
||||
h = ""
|
||||
h << "@ line #{line_num}:\n"
|
||||
h << text.bold(code_object.module? ? "Module" : "Class")
|
||||
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
|
||||
h << bold(code_object.module? ? "Module" : "Class")
|
||||
h << " #{bold('name:')} #{code_object.nonblank_name}"
|
||||
|
||||
if code_object.number_of_candidates > 1
|
||||
h << (text.bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
|
||||
h << (bold("\nNumber of monkeypatches: ") << code_object.number_of_candidates.to_s)
|
||||
h << ". Use the `-a` option to display all available monkeypatches"
|
||||
end
|
||||
h
|
||||
|
@ -145,9 +145,9 @@ class Pry
|
|||
|
||||
def method_sections(code_object)
|
||||
{
|
||||
:owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
|
||||
:visibility => "#{text.bold("Visibility:")} #{code_object.visibility}",
|
||||
:signature => "\n#{text.bold("Signature:")} #{code_object.signature}"
|
||||
:owner => "\n#{bold("Owner:")} #{code_object.owner || "N/A"}\n",
|
||||
:visibility => "#{bold("Visibility:")} #{code_object.visibility}",
|
||||
:signature => "\n#{bold("Signature:")} #{code_object.signature}"
|
||||
}.merge(header_options) { |key, old, new| (new && old).to_s }
|
||||
end
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class Pry
|
|||
pager.puts "Listing all watched expressions:"
|
||||
pager.puts ""
|
||||
expressions.each_with_index do |expr, index|
|
||||
pager.print text.with_line_numbers(expr.to_s, index+1)
|
||||
pager.print with_line_numbers(expr.to_s, index+1)
|
||||
end
|
||||
pager.puts ""
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ class Pry
|
|||
expressions.each do |expr|
|
||||
expr.eval!
|
||||
if expr.changed?
|
||||
output.puts "#{text.blue "watch"}: #{expr.to_s}"
|
||||
output.puts "#{blue "watch"}: #{expr.to_s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,7 +94,7 @@ class Pry
|
|||
|
||||
set_file_and_dir_locals(@file)
|
||||
|
||||
out = "\n#{text.bold('From:')} #{location}:\n\n" <<
|
||||
out = "\n#{bold('From:')} #{location}:\n\n" <<
|
||||
code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted << "\n"
|
||||
|
||||
_pry_.pager.page out
|
||||
|
|
|
@ -26,7 +26,7 @@ class Pry
|
|||
def process
|
||||
raise Pry::CommandError, "No most-recent exception" unless exception
|
||||
|
||||
output.puts "#{text.bold('Exception:')} #{exception.class}: #{exception}\n--"
|
||||
output.puts "#{bold('Exception:')} #{exception.class}: #{exception}\n--"
|
||||
if opts.verbose?
|
||||
output.puts with_line_numbers(backtrace)
|
||||
else
|
||||
|
|
|
@ -71,10 +71,10 @@ class Pry
|
|||
installer.install(name)
|
||||
rescue Errno::EACCES
|
||||
raise CommandError,
|
||||
"Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
|
||||
"Insufficient permissions to install #{green(name)}."
|
||||
rescue Gem::GemNotFoundException
|
||||
raise CommandError,
|
||||
"Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
|
||||
"Gem #{green(name)} not found. Aborting installation."
|
||||
else
|
||||
Gem.refresh
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue