Skip to content

Commit dc011fd

Browse files
committed
Optionally disable colorized output via env
Colorized output is now disabled if the environment variable `OVERCOMMIT_COLOR` is present with the value `0`. Fixes sds#508.
1 parent 09f0550 commit dc011fd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/overcommit/logger.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def bold_warning(*args)
7878
# @param partial [true,false] whether to omit a newline
7979
def color(code, str, partial = false)
8080
send(partial ? :partial : :log,
81-
@out.tty? ? "\033[#{code}m#{str}\033[0m" : str)
81+
colorize? ? "\033[#{code}m#{str}\033[0m" : str)
82+
end
83+
84+
def colorize?
85+
@out.tty? && ENV.fetch('OVERCOMMIT_COLOR', '1') != '0'
8286
end
8387
end
8488
end

spec/overcommit/logger_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@
8080
output.should_not include "\033"
8181
end
8282
end
83+
84+
context 'when colorization is disabled' do
85+
before do
86+
io.stub(:tty?).and_return(true)
87+
end
88+
89+
around do |example|
90+
Overcommit::Utils.with_environment 'OVERCOMMIT_COLOR' => '0' do
91+
example.run
92+
end
93+
end
94+
95+
it 'omits the color escape sequence' do
96+
subject
97+
output.should_not include "\033"
98+
end
99+
end
83100
end
84101

85102
describe '#debug' do

0 commit comments

Comments
 (0)