Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/heroku/helpers/log_displayer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ def display_logs

heroku.read_logs(app, opts) do |chunk|
unless chunk.empty?
if STDOUT.isatty && ENV.has_key?("TERM")
if $stdout.isatty && ENV.has_key?("TERM")
display(colorize(chunk))
else
display(chunk)
$stdout.flush
end
end
end
rescue Errno::EPIPE
rescue Interrupt => interrupt
if STDOUT.isatty && ENV.has_key?("TERM")
if $stdout.isatty && ENV.has_key?("TERM")
display("\e[0m")
end
raise(interrupt)
Expand Down
10 changes: 2 additions & 8 deletions spec/heroku/command/logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,19 @@
end

it "prettifies tty output" do
old_stdout_isatty = $stdout.isatty
stub($stdout).isatty.returns(true)
stderr, stdout = execute("logs")
stderr, stdout = execute("logs") { |sin, sout, serr| sout.stub!(:isatty).and_return(true) }
stderr.should == ""
stdout.should == <<-STDOUT
\e[36m2011-01-01T00:00:00+00:00 app[web.1]:\e[0m test
STDOUT
stub($stdout).isatty.returns(old_stdout_isatty)
end

it "does not use ansi if stdout is not a tty" do
old_stdout_isatty = $stdout.isatty
stub($stdout).isatty.returns(false)
stderr, stdout = execute("logs")
stderr, stdout = execute("logs") { |sin, sout, serr| sout.stub!(:isatty).and_return(false) }
stderr.should == ""
stdout.should == <<-STDOUT
2011-01-01T00:00:00+00:00 app[web.1]: test
STDOUT
stub($stdout).isatty.returns(old_stdout_isatty)
end

it "does not use ansi if TERM is not set" do
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def prepare_command(klass)
command
end

def execute(command_line)
def execute(command_line, &block)
extend RR::Adapters::RRMethods

args = command_line.split(" ")
Expand All @@ -67,6 +67,8 @@ def tty?
end
end

yield $stdin, $stdout, $stderr if block_given?

begin
object.send(method)
rescue SystemExit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change

Expand Down