mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Pager should also respect _pry_.config.color
This commit is contained in:
parent
5d7c887129
commit
2285a83330
2 changed files with 18 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
class Pry
|
||||
class Output
|
||||
attr_reader :_pry_
|
||||
|
||||
def initialize(_pry_)
|
||||
@_pry_ = _pry_
|
||||
end
|
||||
|
@ -10,16 +11,21 @@ class Pry
|
|||
print "#{str.chomp}\n"
|
||||
end
|
||||
|
||||
def print str
|
||||
if _pry_.config.color
|
||||
_pry_.config.output.print str
|
||||
else
|
||||
_pry_.config.output.print Helpers::Text.strip_color str
|
||||
end
|
||||
def print(str)
|
||||
_pry_.config.output.print decolorize_maybe(str)
|
||||
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 method_missing(name, *args, &block)
|
||||
_pry_.config.output.send(name, *args, &block)
|
||||
end
|
||||
|
|
|
@ -153,13 +153,13 @@ class Pry::Pager
|
|||
|
||||
def write(str)
|
||||
if invoked_pager?
|
||||
pager.write str
|
||||
write_to_pager str
|
||||
else
|
||||
@tracker.record str
|
||||
@buffer << str
|
||||
|
||||
if @tracker.page?
|
||||
pager.write @buffer
|
||||
write_to_pager @buffer
|
||||
end
|
||||
end
|
||||
rescue Errno::EPIPE
|
||||
|
@ -176,6 +176,10 @@ class Pry::Pager
|
|||
|
||||
private
|
||||
|
||||
def write_to_pager(text)
|
||||
pager.write @out.decolorize_maybe(text)
|
||||
end
|
||||
|
||||
def invoked_pager?
|
||||
@pager
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue