summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorstrcmp <strcmp@singletonclass.com>2015-08-22 15:11:20 +0100
committerstrcmp <strcmp@singletonclass.com>2015-08-22 15:14:01 +0100
commit65fd1330fd6954711bcc243c643877776c895c04 (patch)
tree09d352e7df1a679f51b44fc4940509dc2c550aa0 /lib
parent4172635d0005a1041b0dcd23d3ef27aad3b64c7c (diff)
downloadpry-65fd1330fd6954711bcc243c643877776c895c04.tar.gz
refactor Pry::Output and add `#tty?` method to it.
Diffstat (limited to 'lib')
-rw-r--r--lib/pry/output.rb76
1 files changed, 38 insertions, 38 deletions
diff --git a/lib/pry/output.rb b/lib/pry/output.rb
index 3ab3deb0..db5402b3 100644
--- a/lib/pry/output.rb
+++ b/lib/pry/output.rb
@@ -1,50 +1,50 @@
-class Pry
- class Output
- attr_reader :_pry_
+class Pry::Output
+ attr_reader :_pry_
- def initialize(_pry_)
- @_pry_ = _pry_
- end
-
- def puts(*objs)
- return print "\n" if objs.empty?
+ def initialize(_pry_)
+ @_pry_ = _pry_
+ @boxed_io = _pry_.config.output
+ end
- objs.each do |obj|
- if ary = Array.try_convert(obj)
- puts(*ary)
- else
- print "#{obj.to_s.chomp}\n"
- end
+ def puts(*objs)
+ return print "\n" if objs.empty?
+ objs.each do |obj|
+ if ary = Array.try_convert(obj)
+ puts(*ary)
+ else
+ print "#{obj.to_s.chomp}\n"
end
-
- nil
end
+ nil
+ end
- def print(*objs)
- objs.each do |obj|
- _pry_.config.output.print decolorize_maybe(obj.to_s)
- end
-
- nil
+ def print(*objs)
+ objs.each do |obj|
+ @boxed_io.print decolorize_maybe(obj.to_s)
end
- alias << print
- alias write print
+ nil
+ end
+ alias << print
+ alias write print
- # If _pry_.config.color is currently false, removes ansi escapes from the string.
- def decolorize_maybe(str)
- if _pry_.config.color
- str
- else
- Helpers::Text.strip_color str
- end
- end
+ def tty?
+ @boxed_io.respond_to?(:tty?) and @boxed_io.tty?
+ end
- def method_missing(name, *args, &block)
- _pry_.config.output.__send__(name, *args, &block)
- end
+ def method_missing(name, *args, &block)
+ @boxed_io.__send__(name, *args, &block)
+ end
+
+ def respond_to_missing?(*a)
+ _pry_.config.respond_to?(*a)
+ end
- def respond_to_missing?(*a)
- _pry_.config.respond_to?(*a)
+ private
+ def decolorize_maybe(str)
+ if _pry_.config.color
+ str
+ else
+ Pry::Helpers::Text.strip_color str
end
end
end