From c6f8d5c632d5609402da6bc49c289798ce872238 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Sun, 20 Jul 2014 17:31:02 -0700 Subject: [PATCH] Revert "Get rid of Code#highlighted" This reverts commit 5599b0a97652cd193d035a75fe58efdf63c18fa4. And fixes jruby-head. https://travis-ci.org/pry/pry/jobs/30420112 --- lib/pry/code.rb | 9 +++++++-- lib/pry/commands/cat/abstract_formatter.rb | 2 +- lib/pry/commands/show_source.rb | 2 +- lib/pry/commands/watch_expression.rb | 2 +- lib/pry/commands/watch_expression/expression.rb | 4 ++-- lib/pry/commands/whereami.rb | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/pry/code.rb b/lib/pry/code.rb index b99f9767..f58189eb 100644 --- a/lib/pry/code.rb +++ b/lib/pry/code.rb @@ -253,7 +253,12 @@ class Pry # @return [String] a formatted representation (based on the configuration of # the object). def to_s - print_to_output("") + print_to_output("", false) + end + + # @return [String] a (possibly highlighted) copy of the source code. + def highlighted + print_to_output("", true) end # Writes a formatted representation (based on the configuration of the @@ -261,7 +266,7 @@ class Pry def print_to_output(output, color=false) @lines.each do |loc| loc = loc.dup - loc.colorize(@code_type) + loc.colorize(@code_type) if color loc.add_line_number(max_lineno_width, color) if @with_line_numbers loc.add_marker(@marker_lineno) if @with_marker loc.indent(@indentation_num) if @with_indentation diff --git a/lib/pry/commands/cat/abstract_formatter.rb b/lib/pry/commands/cat/abstract_formatter.rb index 661f036b..c5546476 100644 --- a/lib/pry/commands/cat/abstract_formatter.rb +++ b/lib/pry/commands/cat/abstract_formatter.rb @@ -8,7 +8,7 @@ class Pry def decorate(content) content.code_type = code_type content.between(*between_lines). - with_line_numbers(use_line_numbers?) + with_line_numbers(use_line_numbers?).highlighted end def code_type diff --git a/lib/pry/commands/show_source.rb b/lib/pry/commands/show_source.rb index f3f069e4..f8e3a5b0 100644 --- a/lib/pry/commands/show_source.rb +++ b/lib/pry/commands/show_source.rb @@ -40,7 +40,7 @@ class Pry # The source for code_object prepared for display. def content_for(code_object) Code.new(code_object.source, start_line_for(code_object)). - with_line_numbers(use_line_numbers?) + with_line_numbers(use_line_numbers?).highlighted end end diff --git a/lib/pry/commands/watch_expression.rb b/lib/pry/commands/watch_expression.rb index 52a88afd..d93b7c72 100644 --- a/lib/pry/commands/watch_expression.rb +++ b/lib/pry/commands/watch_expression.rb @@ -88,7 +88,7 @@ class Pry def add_expression(arguments) expressions << Expression.new(_pry_, target, arg_string) - output.puts "Watching #{Code.new(arg_string)}" + output.puts "Watching #{Code.new(arg_string).highlighted}" end def add_hook diff --git a/lib/pry/commands/watch_expression/expression.rb b/lib/pry/commands/watch_expression/expression.rb index a73b4014..514b95dd 100644 --- a/lib/pry/commands/watch_expression/expression.rb +++ b/lib/pry/commands/watch_expression/expression.rb @@ -6,7 +6,7 @@ class Pry def initialize(_pry_, target, source) @_pry_ = _pry_ @target = target - @source = source.strip + @source = Code.new(source).strip end def eval! @@ -15,7 +15,7 @@ class Pry end def to_s - "#{Code.new(source).strip} => #{value}" + "#{Code.new(source).highlighted.strip} => #{value}" end # Has the value of the expression changed? diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index 695ecc90..ac701645 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -89,7 +89,7 @@ class Pry set_file_and_dir_locals(@file) out = "\n#{text.bold('From:')} #{location}:\n\n" << - code.with_line_numbers(use_line_numbers?).with_marker(marker) << "\n" + code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted << "\n" _pry_.pager.page out end