mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Start using Pry::Code#highlighted
Before this change the watch command was broken because Pry::Code#to_s contained ansi codes which it passed into eval.
This commit is contained in:
parent
5421dbfb34
commit
01785a8020
6 changed files with 18 additions and 12 deletions
|
@ -253,15 +253,20 @@ 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(color=false)
|
||||
print_to_output("", color)
|
||||
end
|
||||
|
||||
# Writes a formatted representation (based on the configuration of the
|
||||
# object) to the given output, which must respond to `#<<`.
|
||||
def print_to_output(output)
|
||||
def print_to_output(output, color=false)
|
||||
@lines.each do |loc|
|
||||
loc = loc.dup
|
||||
loc.colorize(@code_type) if Pry.config.color
|
||||
loc.colorize(@code_type) if color
|
||||
loc.add_line_number(max_lineno_width) if @with_line_numbers
|
||||
loc.add_marker(@marker_lineno) if @with_marker
|
||||
loc.indent(@indentation_num) if @with_indentation
|
||||
|
|
|
@ -79,7 +79,7 @@ class Pry
|
|||
end
|
||||
|
||||
Pry::Pager.with_pager(output) do |pager|
|
||||
@history.print_to_output(pager)
|
||||
@history.print_to_output(pager, _pry_.config.color)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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?).to_s
|
||||
with_line_numbers(use_line_numbers?).highlighted(_pry_.config.color)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -87,8 +87,8 @@ class Pry
|
|||
end
|
||||
|
||||
def add_expression(arguments)
|
||||
expressions << Expression.new(target, arg_string)
|
||||
output.puts "Watching #{Code.new(arg_string)}"
|
||||
expressions << Expression.new(_pry_, target, arg_string)
|
||||
output.puts "Watching #{Code.new(arg_string).highlighted(_pry_.config.color)}"
|
||||
end
|
||||
|
||||
def add_hook
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
class Pry
|
||||
class Command::WatchExpression
|
||||
class Expression
|
||||
attr_reader :target, :source, :value, :previous_value
|
||||
attr_reader :target, :source, :value, :previous_value, :_pry_
|
||||
|
||||
def initialize(target, source)
|
||||
def initialize(_pry_, target, source)
|
||||
@_pry_ = _pry_
|
||||
@target = target
|
||||
@source = Code.new(source).strip
|
||||
end
|
||||
|
||||
def eval!
|
||||
@previous_value = @value
|
||||
@value = Pry::ColorPrinter.pp(target_eval(target, source), "")
|
||||
@value = Pry::ColorPrinter.pp(_pry_, target_eval(target, source), "")
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{source} => #{value}"
|
||||
"#{Code.new(source).highlighted(_pry_.config.color).strip} => #{value}"
|
||||
end
|
||||
|
||||
# Has the value of the expression changed?
|
||||
|
|
|
@ -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).to_s << "\n"
|
||||
code.with_line_numbers(use_line_numbers?).with_marker(marker).highlighted(_pry_.config.color) << "\n"
|
||||
|
||||
stagger_output(out)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue