diff --git a/CHANGELOG.md b/CHANGELOG.md index f49cdb50..f40aef93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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**. diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 01f6db54..733044aa 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -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. diff --git a/lib/pry/commands/cat/exception_formatter.rb b/lib/pry/commands/cat/exception_formatter.rb index b9b1359b..6b3fee89 100644 --- a/lib/pry/commands/cat/exception_formatter.rb +++ b/lib/pry/commands/cat/exception_formatter.rb @@ -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 diff --git a/lib/pry/commands/easter_eggs.rb b/lib/pry/commands/easter_eggs.rb index fafc6d21..9d35f2f2 100644 --- a/lib/pry/commands/easter_eggs.rb +++ b/lib/pry/commands/easter_eggs.rb @@ -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 ! | diff --git a/lib/pry/commands/find_method.rb b/lib/pry/commands/find_method.rb index 8c13c879..52535c17 100644 --- a/lib/pry/commands/find_method.rb +++ b/lib/pry/commands/find_method.rb @@ -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) diff --git a/lib/pry/commands/gem_install.rb b/lib/pry/commands/gem_install.rb index 873e1060..0df27715 100644 --- a/lib/pry/commands/gem_install.rb +++ b/lib/pry/commands/gem_install.rb @@ -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('/') diff --git a/lib/pry/commands/gem_list.rb b/lib/pry/commands/gem_list.rb index e4a5d00e..bb5e0f48 100644 --- a/lib/pry/commands/gem_list.rb +++ b/lib/pry/commands/gem_list.rb @@ -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 diff --git a/lib/pry/commands/gem_search.rb b/lib/pry/commands/gem_search.rb index cac9f3a3..8cbe41ac 100644 --- a/lib/pry/commands/gem_search.rb +++ b/lib/pry/commands/gem_search.rb @@ -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) diff --git a/lib/pry/commands/help.rb b/lib/pry/commands/help.rb index 3f29c2c8..8bd2d8aa 100644 --- a/lib/pry/commands/help.rb +++ b/lib/pry/commands/help.rb @@ -59,7 +59,7 @@ class Pry # @param [Array] 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 diff --git a/lib/pry/commands/install_command.rb b/lib/pry/commands/install_command.rb index acafe7b3..936a7296 100644 --- a/lib/pry/commands/install_command.rb +++ b/lib/pry/commands/install_command.rb @@ -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 diff --git a/lib/pry/commands/list_inspectors.rb b/lib/pry/commands/list_inspectors.rb index c96c3951..9c259a53 100644 --- a/lib/pry/commands/list_inspectors.rb +++ b/lib/pry/commands/list_inspectors.rb @@ -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) diff --git a/lib/pry/commands/list_prompts.rb b/lib/pry/commands/list_prompts.rb index 436f719b..c257de7f 100644 --- a/lib/pry/commands/list_prompts.rb +++ b/lib/pry/commands/list_prompts.rb @@ -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) diff --git a/lib/pry/commands/pry_backtrace.rb b/lib/pry/commands/pry_backtrace.rb index 6795aa32..8d7f59cb 100644 --- a/lib/pry/commands/pry_backtrace.rb +++ b/lib/pry/commands/pry_backtrace.rb @@ -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 diff --git a/lib/pry/commands/show_info.rb b/lib/pry/commands/show_info.rb index a9814b76..37b36371 100644 --- a/lib/pry/commands/show_info.rb +++ b/lib/pry/commands/show_info.rb @@ -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 diff --git a/lib/pry/commands/watch_expression.rb b/lib/pry/commands/watch_expression.rb index d93b7c72..f7d369d3 100644 --- a/lib/pry/commands/watch_expression.rb +++ b/lib/pry/commands/watch_expression.rb @@ -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 diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index 5676c5b9..126721a3 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -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 diff --git a/lib/pry/commands/wtf.rb b/lib/pry/commands/wtf.rb index 2d47dfac..d28d64cb 100644 --- a/lib/pry/commands/wtf.rb +++ b/lib/pry/commands/wtf.rb @@ -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 diff --git a/lib/pry/rubygem.rb b/lib/pry/rubygem.rb index 1da897f3..5c84a325 100644 --- a/lib/pry/rubygem.rb +++ b/lib/pry/rubygem.rb @@ -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