diff --git a/lib/pry/code.rb b/lib/pry/code.rb index 0f435569..f58189eb 100644 --- a/lib/pry/code.rb +++ b/lib/pry/code.rb @@ -257,8 +257,8 @@ class Pry end # @return [String] a (possibly highlighted) copy of the source code. - def highlighted(color=false) - print_to_output("", color) + def highlighted + print_to_output("", true) end # Writes a formatted representation (based on the configuration of the @@ -267,7 +267,7 @@ class Pry @lines.each do |loc| loc = loc.dup loc.colorize(@code_type) if color - loc.add_line_number(max_lineno_width) if @with_line_numbers + 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 output << loc.line diff --git a/lib/pry/code/loc.rb b/lib/pry/code/loc.rb index b14bd1a6..905c7040 100644 --- a/lib/pry/code/loc.rb +++ b/lib/pry/code/loc.rb @@ -59,9 +59,9 @@ class Pry # # @param [Integer] max_width # @return [void] - def add_line_number(max_width = 0) + def add_line_number(max_width = 0, color = false) padded = lineno.to_s.rjust(max_width) - colorized_lineno = Pry::Helpers::BaseHelpers.colorize_code(padded) + colorized_lineno = color ? Pry::Helpers::BaseHelpers.colorize_code(padded) : padded tuple[0] = "#{ colorized_lineno }: #{ line }" end diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb index 31f9d48a..76ef24eb 100644 --- a/lib/pry/color_printer.rb +++ b/lib/pry/color_printer.rb @@ -18,16 +18,14 @@ class Pry end def text(str, width = str.length) - super(*if !Pry.config.color - [str, width] # Don't recolorize output with color [Issue #751] - elsif str.include?("\e[") - ["#{str}\e[0m", width] + if str.include?("\e[") + super "#{str}\e[0m", width elsif str.start_with?('#<') || str == '=' || str == '>' - [highlight_object_literal(str), width] + super highlight_object_literal(str), width else - [CodeRay.scan(str, :ruby).term, width] - end) + super CodeRay.scan(str, :ruby).term, width + end end def pp(obj) @@ -43,7 +41,7 @@ class Pry obj_id = obj.__id__.to_s(16) rescue 0 str = "#<#{klass}:0x#{obj_id}>" - text(Pry.config.color ? highlight_object_literal(str) : str) + text highlight_object_literal(str) end private diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb index 75643843..083d3f59 100644 --- a/lib/pry/commands/hist.rb +++ b/lib/pry/commands/hist.rb @@ -79,7 +79,7 @@ class Pry end _pry_.pager.open do |pager| - @history.print_to_output(pager, _pry_.config.color) + @history.print_to_output(pager, true) end end diff --git a/lib/pry/commands/show_source.rb b/lib/pry/commands/show_source.rb index ce2c0c0b..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?).highlighted(_pry_.config.color) + 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 de514ad9..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).highlighted(_pry_.config.color)}" + 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 fdceae9e..514b95dd 100644 --- a/lib/pry/commands/watch_expression/expression.rb +++ b/lib/pry/commands/watch_expression/expression.rb @@ -11,11 +11,11 @@ class Pry def eval! @previous_value = @value - @value = Pry::ColorPrinter.pp(_pry_, target_eval(target, source), "") + @value = Pry::ColorPrinter.pp(target_eval(target, source), "") end def to_s - "#{Code.new(source).highlighted(_pry_.config.color).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 e7df0e0d..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).highlighted(_pry_.config.color) << "\n" + code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted << "\n" _pry_.pager.page out end diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 8b262dc4..5dade460 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -47,11 +47,7 @@ class Pry end def colorize_code(code) - if Pry.config.color - CodeRay.scan(code, :ruby).term - else - code - end + CodeRay.scan(code, :ruby).term end def highlight(string, regexp, highlight_color=:bright_yellow) @@ -61,7 +57,7 @@ class Pry # formatting def heading(text) text = "#{text}\n--" - Pry.config.color ? "\e[1m#{text}\e[0m": text + "\e[1m#{text}\e[0m" end # have fun on the Windows platform. @@ -110,7 +106,7 @@ class Pry # enabled). Infers where to send the output if used as a mixin. # DEPRECATED. def stagger_output(text, out = nil) - Pry::Pager.new(Pry.config.pager, out || Pry.config.output).page text + Pry.new.pager.page text end end end diff --git a/lib/pry/helpers/documentation_helpers.rb b/lib/pry/helpers/documentation_helpers.rb index 3d1a8990..9f9870e8 100644 --- a/lib/pry/helpers/documentation_helpers.rb +++ b/lib/pry/helpers/documentation_helpers.rb @@ -8,7 +8,6 @@ class Pry module_function def process_rdoc(comment) - return comment unless Pry.config.color comment = comment.dup comment.gsub(/(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, :ruby).term }. gsub(/(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }. @@ -37,7 +36,7 @@ class Pry yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer", "deprecate", "example", "raise"] (yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }. - gsub(/^@(#{yard_tags.join("|")})/) { Pry.config.color ? "\e[33m#{$1}\e[0m": $1 } + gsub(/^@(#{yard_tags.join("|")})/) { "\e[33m#{$1}\e[0m" } end def process_comment_markup(comment) diff --git a/spec/documentation_helper_spec.rb b/spec/documentation_helper_spec.rb index e963d60c..8cab7165 100644 --- a/spec/documentation_helper_spec.rb +++ b/spec/documentation_helper_spec.rb @@ -63,11 +63,6 @@ describe Pry::Helpers::DocumentationHelpers do it "should not remove ++" do @helper.process_rdoc("--\n comment in a bubble\n++").should =~ /\+\+/ end - - it "should do nothing if Pry.config.color is false" do - Pry.config.color = false - @helper.process_rdoc(" 4 + 4\n").should == " 4 + 4\n" - end end end