1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

refactor Pry::Output and add #tty? method to it.

This commit is contained in:
strcmp 2015-08-22 15:11:20 +01:00
parent 4172635d00
commit 65fd1330fd

View file

@ -1,14 +1,13 @@
class Pry class Pry::Output
class Output
attr_reader :_pry_ attr_reader :_pry_
def initialize(_pry_) def initialize(_pry_)
@_pry_ = _pry_ @_pry_ = _pry_
@boxed_io = _pry_.config.output
end end
def puts(*objs) def puts(*objs)
return print "\n" if objs.empty? return print "\n" if objs.empty?
objs.each do |obj| objs.each do |obj|
if ary = Array.try_convert(obj) if ary = Array.try_convert(obj)
puts(*ary) puts(*ary)
@ -16,35 +15,36 @@ class Pry
print "#{obj.to_s.chomp}\n" print "#{obj.to_s.chomp}\n"
end end
end end
nil nil
end end
def print(*objs) def print(*objs)
objs.each do |obj| objs.each do |obj|
_pry_.config.output.print decolorize_maybe(obj.to_s) @boxed_io.print decolorize_maybe(obj.to_s)
end end
nil nil
end end
alias << print alias << print
alias write print alias write print
# If _pry_.config.color is currently false, removes ansi escapes from the string. def tty?
def decolorize_maybe(str) @boxed_io.respond_to?(:tty?) and @boxed_io.tty?
if _pry_.config.color
str
else
Helpers::Text.strip_color str
end
end end
def method_missing(name, *args, &block) def method_missing(name, *args, &block)
_pry_.config.output.__send__(name, *args, &block) @boxed_io.__send__(name, *args, &block)
end end
def respond_to_missing?(*a) def respond_to_missing?(*a)
_pry_.config.respond_to?(*a) _pry_.config.respond_to?(*a)
end end
private
def decolorize_maybe(str)
if _pry_.config.color
str
else
Pry::Helpers::Text.strip_color str
end
end end
end end