Skip to content

Commit

Permalink
Coveralls::Output.no_color = true to completely disable output colori…
Browse files Browse the repository at this point in the history
…ng [Fixes #36]
  • Loading branch information
nickmerwin committed Sep 18, 2013
1 parent 79be43a commit b1a5dcc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/coveralls/output.rb
Expand Up @@ -26,17 +26,24 @@ module Coveralls
# or set this environment variable:
#
# COVERALLS_SILENT
#
# To disable color completely:
#
# Coveralls::Output.no_color = true

module Output
require 'term/ansicolor'
attr_accessor :silent
attr_accessor :silent, :no_color
attr_writer :output
extend self

def output
(defined?(@output) && @output) || $stdout
end

def no_color?
(defined?(@no_color)) && @no_color
end

# Public: Formats the given string with the specified color
# through Term::ANSIColor
#
Expand All @@ -52,10 +59,13 @@ def output
#
# Returns the formatted string.
def format(string, options = {})
if options[:color]
options[:color].split(/\s/).reverse_each do |color|
if Term::ANSIColor.respond_to?(color.to_sym)
string = Term::ANSIColor.send(color.to_sym, string)
unless no_color?
require 'term/ansicolor'
if options[:color]
options[:color].split(/\s/).reverse_each do |color|
if Term::ANSIColor.respond_to?(color.to_sym)
string = Term::ANSIColor.send(color.to_sym, string)
end
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/coveralls/output_spec.rb
Expand Up @@ -57,6 +57,7 @@

describe '.format' do
it "accepts a color argument" do
require 'term/ansicolor'
string = 'Hello'
ansi_color_string = Term::ANSIColor.red(string)
Coveralls::Output.format(string, :color => 'red').should eq(ansi_color_string)
Expand All @@ -77,5 +78,15 @@
multi_formatted_string = Term::ANSIColor.red{ Term::ANSIColor.underline(string) }
Coveralls::Output.format(string, :color => 'red underline').should eq(multi_formatted_string)
end

context "no color" do
before { Coveralls::Output.no_color = true }

it "does not add color to string" do
unformatted_string = "Hi Doggie!"
Coveralls::Output.format(unformatted_string, :color => 'red').
should eq(unformatted_string)
end
end
end
end

0 comments on commit b1a5dcc

Please sign in to comment.