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
|
#### 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.
|
* Add Pry::Testable, an improved modular replacement for PryTestHelpers.
|
||||||
**breaking change**.
|
**breaking change**.
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,14 @@ class Pry
|
||||||
command_set.to_hash
|
command_set.to_hash
|
||||||
end
|
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
|
def text
|
||||||
Pry::Helpers::Text
|
Pry::Helpers::Text
|
||||||
end
|
end
|
||||||
|
@ -264,6 +272,7 @@ class Pry
|
||||||
|
|
||||||
include Pry::Helpers::BaseHelpers
|
include Pry::Helpers::BaseHelpers
|
||||||
include Pry::Helpers::CommandHelpers
|
include Pry::Helpers::CommandHelpers
|
||||||
|
include Pry::Helpers::Text
|
||||||
|
|
||||||
# Instantiate a command, in preparation for calling it.
|
# Instantiate a command, in preparation for calling it.
|
||||||
# @param [Hash] context The runtime context to use with this command.
|
# @param [Hash] context The runtime context to use with this command.
|
||||||
|
|
|
@ -4,6 +4,7 @@ class Pry
|
||||||
attr_reader :ex
|
attr_reader :ex
|
||||||
attr_reader :opts
|
attr_reader :opts
|
||||||
attr_reader :_pry_
|
attr_reader :_pry_
|
||||||
|
include Pry::Helpers::Text
|
||||||
|
|
||||||
def initialize(exception, _pry_, opts)
|
def initialize(exception, _pry_, opts)
|
||||||
@ex = exception
|
@ex = exception
|
||||||
|
@ -66,9 +67,9 @@ class Pry
|
||||||
|
|
||||||
def header
|
def header
|
||||||
unindent %{
|
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
|
end
|
||||||
|
|
|
@ -86,7 +86,7 @@ TEXT
|
||||||
prev_color = _pry_.config.color
|
prev_color = _pry_.config.color
|
||||||
_pry_.config.color = true
|
_pry_.config.color = true
|
||||||
|
|
||||||
picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
|
picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| red(s) }
|
||||||
____ _______________________
|
____ _______________________
|
||||||
/ \ | A W G |
|
/ \ | A W G |
|
||||||
/ O O \ | N I O N ! |
|
/ O O \ | N I O N ! |
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Pry
|
||||||
# @param [Array] matches
|
# @param [Array] matches
|
||||||
def show_search_results(matches)
|
def show_search_results(matches)
|
||||||
if matches.empty?
|
if matches.empty?
|
||||||
output.puts text.bold("No Methods Matched")
|
output.puts bold("No Methods Matched")
|
||||||
else
|
else
|
||||||
print_matches(matches)
|
print_matches(matches)
|
||||||
end
|
end
|
||||||
|
@ -88,7 +88,7 @@ class Pry
|
||||||
|
|
||||||
# Print matched methods for a class
|
# Print matched methods for a class
|
||||||
def print_matches_for_class(klass, grouped)
|
def print_matches_for_class(klass, grouped)
|
||||||
output.puts text.bold(klass.name)
|
output.puts bold(klass.name)
|
||||||
grouped[klass].each do |method|
|
grouped[klass].each do |method|
|
||||||
header = method.name_with_owner
|
header = method.name_with_owner
|
||||||
output.puts header + additional_info(header, method)
|
output.puts header + additional_info(header, method)
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Pry
|
||||||
|
|
||||||
def process(gem)
|
def process(gem)
|
||||||
Rubygem.install(gem)
|
Rubygem.install(gem)
|
||||||
output.puts "Gem `#{ text.green(gem) }` installed."
|
output.puts "Gem `#{ green(gem) }` installed."
|
||||||
require gem
|
require gem
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
require_path = gem.split('-').join('/')
|
require_path = gem.split('-').join('/')
|
||||||
|
|
|
@ -21,10 +21,10 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
versions = specs.each_with_index.map do |spec, index|
|
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
|
end
|
||||||
|
|
||||||
output.puts "#{text.default gem} (#{versions.join ', '})"
|
output.puts "#{default gem} (#{versions.join ', '})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ private
|
||||||
def list_as_string(gems, limit = 10)
|
def list_as_string(gems, limit = 10)
|
||||||
gems[0..limit-1].map do |gem|
|
gems[0..limit-1].map do |gem|
|
||||||
name, version, info = gem.values_at 'name', 'version', 'info'
|
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.join
|
||||||
end
|
end
|
||||||
Pry::Commands.add_command(self)
|
Pry::Commands.add_command(self)
|
||||||
|
|
|
@ -59,7 +59,7 @@ class Pry
|
||||||
# @param [Array<Pry::Command>] commands
|
# @param [Array<Pry::Command>] commands
|
||||||
# @return [String] The generated help string.
|
# @return [String] The generated help string.
|
||||||
def help_text_for_commands(name, commands)
|
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}"
|
" #{command.options[:listing].to_s.ljust(18)} #{command.description.capitalize}"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,21 +16,21 @@ class Pry
|
||||||
command = find_command(name)
|
command = find_command(name)
|
||||||
|
|
||||||
unless command
|
unless command
|
||||||
output.puts "Command #{ text.green(name) } is not found"
|
output.puts "Command #{ green(name) } is not found"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if command_dependencies_met?(command.options)
|
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
|
return
|
||||||
end
|
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 = Array(command.options[:requires_gem])
|
||||||
|
|
||||||
gems_to_install.each do |g|
|
gems_to_install.each do |g|
|
||||||
next if Rubygem.installed?(g)
|
next if Rubygem.installed?(g)
|
||||||
output.puts "Installing #{ text.green(g) } gem..."
|
output.puts "Installing #{ green(g) } gem..."
|
||||||
Rubygem.install(g)
|
Rubygem.install(g)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,14 +38,14 @@ class Pry
|
||||||
begin
|
begin
|
||||||
require g
|
require g
|
||||||
rescue LoadError
|
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 += " Aborting command installation\n"
|
||||||
fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
|
fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
|
||||||
raise CommandError, fail_msg
|
raise CommandError, fail_msg
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Pry::Command::ListInspectors < Pry::ClassCommand
|
||||||
def process
|
def process
|
||||||
output.puts heading("Available inspectors") + "\n"
|
output.puts heading("Available inspectors") + "\n"
|
||||||
inspector_map.each do |name, inspector|
|
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 selected_inspector?(inspector) ? selected_text : ""
|
||||||
output.puts inspector[:description]
|
output.puts inspector[:description]
|
||||||
output.puts
|
output.puts
|
||||||
|
@ -25,7 +25,7 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def selected_text
|
def selected_text
|
||||||
text.red " (selected) "
|
red " (selected) "
|
||||||
end
|
end
|
||||||
|
|
||||||
def selected_inspector?(inspector)
|
def selected_inspector?(inspector)
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Pry::Command::ListPrompts < Pry::ClassCommand
|
||||||
def process
|
def process
|
||||||
output.puts heading("Available prompts") + "\n"
|
output.puts heading("Available prompts") + "\n"
|
||||||
prompt_map.each do |name, prompt|
|
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 selected_prompt?(prompt) ? selected_text : ""
|
||||||
output.puts prompt[:description]
|
output.puts prompt[:description]
|
||||||
output.puts
|
output.puts
|
||||||
|
@ -25,7 +25,7 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def selected_text
|
def selected_text
|
||||||
text.red " (selected) "
|
red " (selected) "
|
||||||
end
|
end
|
||||||
|
|
||||||
def selected_prompt?(prompt)
|
def selected_prompt?(prompt)
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Pry
|
||||||
BANNER
|
BANNER
|
||||||
|
|
||||||
def process
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -100,11 +100,11 @@ class Pry
|
||||||
# object types: methods, modules, commands, procs...
|
# object types: methods, modules, commands, procs...
|
||||||
def header(code_object)
|
def header(code_object)
|
||||||
file_name, line_num = file_and_line_for(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 << 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"
|
"#{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
|
h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -133,11 +133,11 @@ class Pry
|
||||||
def module_header(code_object, line_num)
|
def module_header(code_object, line_num)
|
||||||
h = ""
|
h = ""
|
||||||
h << "@ line #{line_num}:\n"
|
h << "@ line #{line_num}:\n"
|
||||||
h << text.bold(code_object.module? ? "Module" : "Class")
|
h << bold(code_object.module? ? "Module" : "Class")
|
||||||
h << " #{text.bold('name:')} #{code_object.nonblank_name}"
|
h << " #{bold('name:')} #{code_object.nonblank_name}"
|
||||||
|
|
||||||
if code_object.number_of_candidates > 1
|
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"
|
h << ". Use the `-a` option to display all available monkeypatches"
|
||||||
end
|
end
|
||||||
h
|
h
|
||||||
|
@ -145,9 +145,9 @@ class Pry
|
||||||
|
|
||||||
def method_sections(code_object)
|
def method_sections(code_object)
|
||||||
{
|
{
|
||||||
:owner => "\n#{text.bold("Owner:")} #{code_object.owner || "N/A"}\n",
|
:owner => "\n#{bold("Owner:")} #{code_object.owner || "N/A"}\n",
|
||||||
:visibility => "#{text.bold("Visibility:")} #{code_object.visibility}",
|
:visibility => "#{bold("Visibility:")} #{code_object.visibility}",
|
||||||
:signature => "\n#{text.bold("Signature:")} #{code_object.signature}"
|
:signature => "\n#{bold("Signature:")} #{code_object.signature}"
|
||||||
}.merge(header_options) { |key, old, new| (new && old).to_s }
|
}.merge(header_options) { |key, old, new| (new && old).to_s }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ class Pry
|
||||||
pager.puts "Listing all watched expressions:"
|
pager.puts "Listing all watched expressions:"
|
||||||
pager.puts ""
|
pager.puts ""
|
||||||
expressions.each_with_index do |expr, index|
|
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
|
end
|
||||||
pager.puts ""
|
pager.puts ""
|
||||||
end
|
end
|
||||||
|
@ -81,7 +81,7 @@ class Pry
|
||||||
expressions.each do |expr|
|
expressions.each do |expr|
|
||||||
expr.eval!
|
expr.eval!
|
||||||
if expr.changed?
|
if expr.changed?
|
||||||
output.puts "#{text.blue "watch"}: #{expr.to_s}"
|
output.puts "#{blue "watch"}: #{expr.to_s}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,7 +94,7 @@ class Pry
|
||||||
|
|
||||||
set_file_and_dir_locals(@file)
|
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"
|
code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted << "\n"
|
||||||
|
|
||||||
_pry_.pager.page out
|
_pry_.pager.page out
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Pry
|
||||||
def process
|
def process
|
||||||
raise Pry::CommandError, "No most-recent exception" unless exception
|
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?
|
if opts.verbose?
|
||||||
output.puts with_line_numbers(backtrace)
|
output.puts with_line_numbers(backtrace)
|
||||||
else
|
else
|
||||||
|
|
|
@ -71,10 +71,10 @@ class Pry
|
||||||
installer.install(name)
|
installer.install(name)
|
||||||
rescue Errno::EACCES
|
rescue Errno::EACCES
|
||||||
raise CommandError,
|
raise CommandError,
|
||||||
"Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
|
"Insufficient permissions to install #{green(name)}."
|
||||||
rescue Gem::GemNotFoundException
|
rescue Gem::GemNotFoundException
|
||||||
raise CommandError,
|
raise CommandError,
|
||||||
"Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
|
"Gem #{green(name)} not found. Aborting installation."
|
||||||
else
|
else
|
||||||
Gem.refresh
|
Gem.refresh
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue