Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lib/overcommit/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def bold_warning(*args)
# @param partial [true,false] whether to omit a newline
def color(code, str, partial = false)
send(partial ? :partial : :log,
@out.tty? ? "\033[#{code}m#{str}\033[0m" : str)
colorize? ? "\033[#{code}m#{str}\033[0m" : str)
end

def colorize?
@out.tty? && ENV.fetch('OVERCOMMIT_COLOR', '1') != '0'
end
end
end
17 changes: 17 additions & 0 deletions spec/overcommit/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@
output.should_not include "\033"
end
end

context 'when colorization is disabled' do
before do
io.stub(:tty?).and_return(true)
end

around do |example|
Overcommit::Utils.with_environment 'OVERCOMMIT_COLOR' => '0' do
example.run
end
end

it 'omits the color escape sequence' do
subject
output.should_not include "\033"
end
end
end

describe '#debug' do
Expand Down